【发布时间】:2014-03-06 17:24:40
【问题描述】:
我对下面给出的 Python 代码感到困惑,其中函数在定义之前被调用。是否可以?是不是因为函数没有返回值?
from Circle import Circle
def main():
myCircle = Circle()
n = 5
printAreas(myCircle, n) #The function is called here
def printAreas(c, times):
xxxx
xxxx
main()
【问题讨论】:
-
是什么让你认为函数在定义之前被调用?
-
不是。它在 main 被调用时被调用,它位于程序的最后。
-
尝试将调用移动到
main在printAreas的定义之前,如:main()<NEWLINE>def printAreas(...): ...。
标签: python interpreter