1

I'm new to python, and while it's a pretty simple language, I'm having a hard time finding a solid and easy to read language reference that lists all the supported build-in methods and libraries that come with the installation. The main documentation site is confusing. There's more info about what's deprecated than what's recommended. I tried using pydoc to find method usage. For example, I want to see a simple list of all the methods that are part of the string class (e.g. replace(), toupper(), etc). But I'm not sure how to use it to list the methods, or to list a method and its usage. What do people use for a quick reference that works?

When I do something like 'pydoc string', I see a message that says "Warning: most of the code you see here isn't normally used nowadays. Beginning with Python 1.6, many of these functions are implemented as methods on the standard string object. They used to be implemented by a built-in module called strop, but strop is now obsolete itself."

So while there's info about the method replace() there, I'm worried that it's not the right info based on that warning. How can I see the methods of the standard string object?

22
  • 1
    you can use dir(yourObject) to see all it's methods and then play with them. E.g. dir("I am a string") Commented Aug 15, 2016 at 19:16
  • 2
    look up how to enter the python shell then just type dir("s") and it should output this: ['gt', 'hash', 'init', 'le', 'len', 'lt', 'mod', 'mul', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'rmod', 'rmul', 'setattr', 'sizeof', 'str', 'subclasshook', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format'] .. just a few of them since I cant post too much in comments Commented Aug 15, 2016 at 19:21
  • 1
    You see that warning because you are looking at the documentation for a module, not a class. You should be using pydoc str. You can also use the help function in the Python console. Just as with dir, you can pass it any object, but be aware that passing it a string is a special case that makes it look up the contents of the string rather than the string object itself. @limbo Commented Aug 15, 2016 at 19:33
  • 1
    @limbo: You probably would have noticed it if you had read the documentation :-) Commented Aug 15, 2016 at 19:40
  • 1
    @u84six "Someone" told you something that's severely outdated. Believe me, I stuck with Python 2 longer than most, but it's 2016 now. "Most 3rd party modules don't work with it" hasn't been true since 2012. I'm guessing that person doesn't actually have much experience working with Python 3. py3readiness.org Commented Aug 15, 2016 at 19:49

2 Answers 2

2

Documentation about standard functions:

https://docs.python.org/2/library/functions.html

Documentation about standard libraries:

https://docs.python.org/2/library/

Sign up to request clarification or add additional context in comments.

Comments

2

You could use dir() and help(). i.e. :

From python shell :

>>> import math
>>> dir(math)
['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
>>> help(math.tan)

Will print :

Help on built-in function tan in module math:

tan(...)
    tan(x)

    Return the tangent of x (measured in radians).

(press "q" to exit the help page)

Hope it helps.

EDIT

Another solution from the shell :

$ python -m pydoc sys

Then press "q" to exit.

3 Comments

And why "should" you use this over, say, the online documentation?
You could*. It is a solution. (sorry my bad english) It will be as the user like.
Fair point -- upvoted. Just making sure we aren't missing the real issue here which seems to be a localized dislike of the online docs caused by (1.) using a severely outdated version and (2.) confusing the string module with string objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.