What are the parentheses for at the end of Python method names?

后端 未结 3 1351
醉梦人生
醉梦人生 2020-12-09 22:57

I\'m a beginner to Python and programming in general. Right now, I\'m having trouble understanding the function of empty parentheses at the end of method names, built-in or

3条回答
  •  清歌不尽
    2020-12-09 23:26

    upper() is a command asking the upper method to run, while upper is a reference to the method itself. For example,

    upper2 = 'Michael'.upper
    upper2() # does the same thing as 'Michael'.upper() !
    

提交回复
热议问题