Skip to content

Python print methods of object | Example code

  • by

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

A 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 programming

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 or suggestions on this Python object code.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

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

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading