python中函数后面的小括号的作用


 

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

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM