English

Is an object of a class mutable? Why/why not?

Advertisements
Advertisements

Question

Is an object of a class mutable? Why/why not?

Short Answer
Advertisements

Solution

Yes. A class object (instance) is generally mutable because its attributes can be added, modified or deleted after the object is created.

student.name = "Aman"   # Add/modify an attribute
del student.name         # Delete an attribute

The object's namespace changes; therefore, the object is mutable.

shaalaa.com
  Is there an error in this question or solution?
Chapter 3: Classes in Python - EXERCISE [Page 62]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 3 Classes in Python
EXERCISE | Q 5. | Page 62
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×