How to check the methods of one certain object in Python?

My question is: how to check the methods of one certain object in Python?
For example, I know there is one method for String: count()
And I found it listed here:

But while I was searching in python.org, I did not find it.
Maybe I did not find the right page. So could you tell me the right place for checking the methods?
Thanks.

Hello, @tomliuwhite, and welcome to the Python Forum!

It can be found in Python 3 Documentation.

See Built-in Types: String Methods: str.count(sub[, start[, end]]).

EDITED on December 7, 2021 to add the customary welcome.

2 Likes

You can find all the methods of str objects in the official Python docs under str methods; you can see that count is listed, along with all the others. As a sidenote, to see the methods (and other attributes) of any arbitrary object in Python, you can call dir() on it, e.g. dir(str()).

2 Likes

Great, that is helpful. Thanks.

1 Like

While in interactive interpreter you can list all the methods of type or variable by entering name followed by punctuation and pressing TAB two times:

>>> str.     # TAB two times
str.capitalize(   str.format(       str.isidentifier( str.ljust(        str.replace(      str.splitlines(
str.casefold(     str.format_map(   str.islower(      str.lower(        str.rfind(        str.startswith(
str.center(       str.index(        str.isnumeric(    str.lstrip(       str.rindex(       str.strip(
str.count(        str.isalnum(      str.isprintable(  str.maketrans(    str.rjust(        str.swapcase(
str.encode(       str.isalpha(      str.isspace(      str.mro(          str.rpartition(   str.title(
str.endswith(     str.isascii(      str.istitle(      str.partition(    str.rsplit(       str.translate(
str.expandtabs(   str.isdecimal(    str.isupper(      str.removeprefix( str.rstrip(       str.upper(
str.find(         str.isdigit(      str.join(         str.removesuffix( str.split(        str.zfill(
>>> str.

If you need ‘quick look’ what particular method do you can use built-in help (for comprehensive information documentation mentioned in earlier posts is preferred):

>>> help(str.zfill)
Help on method_descriptor:

zfill(self, width, /)
    Pad a numeric string with zeros on the left, to fill a field of the given width.

    The string is never truncated.
2 Likes

Great, it is very helpful, thanks!

1 Like