Python print methods of object | Example code

The simplest method is to use dir(object_name) to get all the methods available for that object and use the print method to print it.

Python print methods of object example

Simple example code uses the built-in dir() function to get a list of all the attributes a module has. Try this at the command line to see how it works.

>>> import moduleName
>>> dir(moduleName)

Or in programing

import pandas as pd

res = dir(pd)
print(res)

Print the method of the String object

a = "I am a string"

res = dir(a)
print(res)

Output:

Python print methods of object

Another example

The simplest way to get a list of methods of any object is to use the help() command.

help(object)

It will list out all the available/important methods associated with that object.

For example:

help(str)
# or
res = help(str)
print(res)

Do comment if you have any doubts and suggestions on this Python object code.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.