mod08 - Python Object-Oriented Programming Flashcards
What is data encapsulation?
Binding data into a single object.
What is data hiding?
Access to an object’s data.
Object’s ability to hide its data attributes from code that is outside of the object.
What is inheritance?
Makes a new object based on an existing object.
What is polymorphism?
Object’s ability to take different forms.
Allows subclasses to have methods with the same names as methods in their superclasses.
What is __init__()?
Constructor AKA the initializer. Does not return the new instance of a class.
What is __del__()?
Deconstructor
What is __new__()?
First step of instance creation. Unlike __init__(), this dunder method RETURNS the new instance of a class.
What is the difference between __str__() and __repr__()?
__str__() returns a human-readable string representation of an object.
__repr__() returns the official object representation in string format. This can be used to reconstruct the object.
What is __eq__()?
Compares two objects using ==
What is the purpose of an accessor method?
It is used to access hidden data in the object. If a setter method isn’t used alongside the accessor method, it is known as a read-only attribute.
What is the purpose of a mutator method?
It is used to modify the hidden value of an object.