How can I find the methods or attributes of an object in python?
Answer / chaitanya
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']
| Is This Answer Correct ? | 0 Yes | 0 No |
What is meta class in python?
Explain what is the common way for the flask script to work?
What is a 4 tuple?
Python read a single character from the user?
Comparison operators != Is not equal to in python?
Explain accessor and mutator methods in python?
Explain the //, %, and ** operators in python?
Is python a compiled or interpreted language?
Is python faster than python2?
Which databases are supported by python?
What is @property in python?
How do you calculate the length of a string?