源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

python缩进区别分析

  • 时间:2021-08-25 02:58 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:python缩进区别分析
仔细观察下面两个python程序,代码一模一样,但是运行的结果却不同,就是因为最后一行return缩进的不同
[u]复制代码[/u] 代码如下:
def powersum(power, *args): '''Return the sum of each argument raised to specified power.''' total = 0 for i in args: total += pow(i, power) return total
运行时输入powersum(2,3,4)输出25(3的平方加上4的平方)
[u]复制代码[/u] 代码如下:
def powersum(power, *args): '''Return the sum of each argument raised to specified power.''' total = 0 for i in args: total += pow(i, power) return total
运行时输入powersum(2,3,4)输出9(3的平方) 由此可见,对于python编写代码时,不能随意的缩进
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部