python缩进区别

时间:2014-02-12 22:36:58   收藏:0   阅读:499

仔细观察下面两个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编写代码时,不能随意的缩进

原文:http://blog.csdn.net/woailvmengmeng/article/details/19110125

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!