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 |
Shade some light on the modes in python programming environment.
How can we make a executable file with python script?
What is flask & its benefits?
What is set when we have to use?
Write a program to check for prime number?
What is syntax in python programming?
Is numpy faster than python?
Why is lambda used in python?
What types are iterable in python?
What is the difference between range and xrange functions?
What are variables in python?
How the memory is managed in python?