Take the 2-minute tour ×

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 only call it as a method like "hi".upper() instead of upper("hi").
So one could assume that any method will be indicated as a function in the docstrings of the built in modules. Yet when I do help('list') , methods of the list class are indicated as methods in the docstrings!!
Why is this so? Only because the person who wrote the doctrings was inconsistent or that different people wrote it? Or do these methods(the ones called 'functions' versus the ones called 'methods' in the docstrings) actually have different properties?

share|improve this question
add comment

5 Answers

up vote 2 down vote accepted

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):
NameError: name 'upper' is not defined
>>> 'hi'.upper() # method from the str type
>>> from string import upper
>>> upper('hi') # function from the string module
share|improve this answer
Thnx. Ok, so str is the name of a class defined in the module _builtin_ while string is the name of a module. Why did they make another string module when there is already a class defined inside the _builtin_ module? –  Bentley4 Apr 3 '12 at 22:06
@Bentley4 The string module has a lot of useful stuff for string processing that wouldn't make much sense inside the str class. Stuff like: constants (digits, uppercase characters), templates, formatters ... More info here –  juliomalegria Apr 4 '12 at 1:16
add comment

You mean to do help('str'), not help('string'). str is a type, string is a module providing functions for working with strings.

share|improve this answer
add comment

You are creating an instance of that object and then calling help on that instance.

So these all work:


Help grabs the docstring for that instance, and gives it back to you. When you create your own objects, you can put in useful docstrings or whatever you want.

share|improve this answer
add comment

There's nothing wrong with what you see.

>>> help('string')

Will show you the string module documentation. And it looks like there's an upper function inside:

>>> import string
>>> string.upper('hello')

I'd say that this upper is the same that is called if you do:

>>> 'hello'.upper()

But I'm not sure.

Notice that a string '' is a str type not a string type. This means that you're probably looking for:

>>> help('str')

And here you'll see too the str.upper method.

share|improve this answer
add comment

This is because 'string' is a string. So is 'list'

To get a similar result for lists, try help([])

share|improve this answer
No... it is perfectly valid to do help('list') to get help on a list –  David Robinson Apr 3 '12 at 17:45
(Please try it) –  David Robinson Apr 3 '12 at 17:46
Wow... I did not know that. x = 'list' and then help(x). That is some unexpected behavior! –  veiset Apr 3 '12 at 17:53
-1 sorry but this is wrong. Try before answering –  juliomalegria Apr 3 '12 at 18:00
@veiset: It looks like strings are the one kind of object you can't get help on by calling it on an instance –  David Robinson Apr 3 '12 at 18:04
add comment

Your Answer


