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

后端 未结 3 1359
醉梦人生
醉梦人生 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:30

    the parentheses indicate that you want to call the method

    upper() returns the value of the method applied to the string

    if you simply say upper, then it returns a method, not the value you get when the method is applied

    >>> print "This string will now be uppercase".upper
    
    >>> 
    

提交回复
热议问题