What are attributes and methods in a python class?



What are attributes and methods in a python class?..

Answer / Piyush Gupta

In Python, attributes represent data members or variables associated with an object of a class. Methods are functions that are bound to objects of a class. They perform actions on the data stored in the attributes.nExample of class definition:n```pythonnclass MyClass:n def __init__(self, attr1, attr2):n self.attr1 = attr1n self.attr2 = attr2n def my_method(self):n return self.attr1 + self.attr2n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

How do I sleep in python?

1 Answers  


When you need ordered container of things, which will be manipulated, use lists?

1 Answers  


What does “list comprehension” mean? How does it work and how can I use it?

1 Answers  


Does flask work with python 3?

1 Answers  


What is python mapping?

1 Answers  


Which python library is built on top of matplotlib and pandas to ease data plotting?

3 Answers  


What is a numpy array?

1 Answers  


What are the built-in data-types in python?

1 Answers  


What is the dictionary?

1 Answers  


Is javascript harder than python?

1 Answers  


What is python explain the advantages of using python?

1 Answers  


What is a metaclass in Python?

1 Answers  


Categories