Methods or attributes of an object in python

How can I find the methods or attributes of an object in python?

- Built-in dir() function of Python ,on an instance shows the instance variables as well as the methods and class attributes defined by the instance's class and all its base classes alphabetically. So by any object as argument to dir() we can find all the methods & attributes of the object’s class.
- Following code snippet shows dir() at work :
class Employee:
def __init__(self,name,empCode,pay):
self.name=name
self.empCode=empCode
self.pay=pay

print("dir() listing all the Methods & attributes of class Employee")
print dir(e)
-----------------------------------------------------
Output
dir() listing all the Methods & attributes of class Employee
[ '__init__', 'empCode', 'name', 'pay']
How do I convert a string to a number?
How do I convert a string to a number? - Python contains several built-in functions to convert values from one data type to another data type.......
What is a negative index in python?
What is a negative index in python? - Python arrays & list items can be accessed with positive or negative numbers (also known as index)........
How do you make an array in Python?
How do you make an array in Python? - The array module contains methods for creating arrays of fixed types with homogeneous data types. Arrays are slower then list......
Post your comment