在Python函数中只使用“从上到下”的顺序?

时间:2016-01-05 11:05:47

标签: python

我的脚本运行良好。我做了一些改变并遇到了问题。搜索它并找不到答案。

这一切都在3.4罚款。

(for code in files, not for interactive mode)
(I know that in interactive mode it will be mistake):

> my_func() 
>def my_func()
-> OK

 With python 3.5 I have:

>my_func()
>def my_func()
-> NameError: name 'my_func' is not defined

Only just that way working now:

>def my_func()
>my_func()
-> OK

screenshot example 哪里有问题?

1 个答案:

答案 0 :(得分:3)

好吧,我的朋友,你必须在调用它之前定义它。

def my_func()应始终在my_func()之前,否则该功能无法被识别为其通话中的现有功能。