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