1、



>>> def a():
print("hello world!")


>>> a
<function a at 0x000002CE49DCB550>
>>> a()
hello world!


 

2、



>>> def a():
print("hello world!")
def b():
print("xxxxxx!")
return b

>>> a()
hello world!
<function a.<locals>.b at 0x0000020074A8F040>
>>> a()()
hello world!
xxxxxx!


 

3、



>>> def a():
print("hello world!")
def b():
print("xxxxxx!")
return b()

>>> a()
hello world!
xxxxxx!


 

4、



>>> x = 10
>>> def a():
global x
x = 1000000
print(x)


>>> a
<function a at 0x000002787AF9B550>
>>> x
10
>>> a()
1000000
>>> x
1000000


小括号的作用表示执行函数。