Python 此函数执行了多少次
for循环是否意味着应该执行循环的时间?如果是这样的话,在给定的情况下,由于range()函数的约束,它不是应该执行(3-1)次而不是3次吗?或者它是按0、1、2这样的顺序执行的 for循环将迭代3次,因为范围中有3个元素:Python 此函数执行了多少次,python,function,python-3.x,Python,Function,Python 3.x,for循环是否意味着应该执行循环的时间?如果是这样的话,在给定的情况下,由于range()函数的约束,它不是应该执行(3-1)次而不是3次吗?或者它是按0、1、2这样的顺序执行的 for循环将迭代3次,因为范围中有3个元素: def raiseToPower(base, exp): total = 1 for count in range(exp): total = total * base return total print
def raiseToPower(base, exp):
total = 1
for count in range(exp):
total = total * base
return total
print ("returned from raiseToPower: %i" % raiseToPower(2,3) )
for循环将迭代3次,因为范围中有3个元素:
def raiseToPower(base, exp):
total = 1
for count in range(exp):
total = total * base
return total
print ("returned from raiseToPower: %i" % raiseToPower(2,3) )
如果在循环中放入print(count)
,则内部发生的事情将非常清楚,函数本身也将执行一次。如果在循环中放入print(count)
,则内部发生的事情将非常清楚,函数本身也将执行一次。