When I type help(\'string\')
in the python interpreter I get information about the string class. There,upper()
is indicated as a function. Yet I can on
When you searched for help('string')
, you were looking for the docstrings of the string
module. If you do help(str)
or help('str')
you'll get the docstrings of the str
type, and here upper
appears as a method!
As you can see here, the function upper
from the string
module is actually a function and not a method:
>>> upper('hi')
Traceback (most recent call last):
File "", line 1, in
NameError: name 'upper' is not defined
>>> 'hi'.upper() # method from the str type
'HI'
>>> from string import upper
>>> upper('hi') # function from the string module
'HI'