python是自上而下运行的,也就是从上面到下面一步步运行的,今天就来测试一下python的运行顺序。
1.首先测试函数的运行顺序。
(1)测试1.函数在上面定义,在下面调用
def hello():
print("hello world")
hello()
#输出结果:hello world
(2)测试2:函数在下面定义,在上面调用
hello()
def hello():
print("hello world")
#运行结果:NameError: name 'hello' is not defined
总结1:函数调用只能在定义函数的下面
2.测试类的运行顺序
(1)下面的类引用上面的类
class Dog()