当前位置: 移动技术网 > IT编程>脚本编程>Python > python缩进区别分析

python缩进区别分析

2019年04月01日  | 移动技术网IT编程  | 我要评论

属牛的人2013年运程大全及破解,厚德蜂胶多少钱一盒,大s宣布怀孕

仔细观察下面两个python程序,代码一模一样,但是运行的结果却不同,就是因为最后一行return缩进的不同

复制代码 代码如下:

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的平方)
复制代码 代码如下:

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编写代码时,不能随意的缩进

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网