Search code examples
pythondocumentation

How to find/read documentation on methods and modules in python?


I know that if you want to read documentation on functions it would look something like this:

print(function_name.__doc__)

or something like this:

print(help(function_name)

is there any possible way to find documentation on methods? Because when I tried to find information on .upper() or .lower() it would not simply work. I hope i'm not mixing terminology here.. and it's really called a method.

print(upper.__doc__) # print(help(lower)

dose not work .... and it's fine, these methods are very simple to understand... but what if we start using something like regex where there are many methods that look seemingly the same...but actually not.

example: re.findall() or re.search()

I would like to know what re(regex) module does or what findall or search method does... is there a possible way to do this without leaving your IDE?

I am extremely sorry, I'm very new to the language but I would love to get better without relying on "howto" videos or articles and finding out how to pull out documentation in different instances is very important for that matter.


Solution

  • upper or lower are methods that act on string type. try this:
    print(help("".upper)) or
    print("".upper.__doc__) or
    print(str.upper.__doc__)

    Another example: print (append.__doc__) gives you an error.

    but this works:
    print(list.append.__doc__)

    If you want to read the documentation on methods that are not builtin, just import the module and look for doc on that method. For instance.

    import re
    print(re.findall.__doc__)
    

    Package information can be obtained using doc as well.

    print(re.__doc__)