Classes and OOP Flashcards
What is a class?
A class is a blueprint for an object in python, containing all properties, attributes, methods etc.
Do classes create their own scope?
No, one must be very explicit when referring to things inside the class.
What are the three main ideas of OOP?
Inheritance: the ability for a new class to specialise/modify the behaviour of existing classes. Polymorphism, dynamic binding and duck typing: The ability to use an instance without regard for its type Data encapsulation and private attributes
What do you call a class that you inherit from?
parent/super class
What is a static method?
A function defined inside a class, does not operate on the instance.
What is a Class method?
A method operating on the class itself as opposed to an instance.
How would you make a class attribute private?
self.__ = …
Can private attributes be accessed outside the class?
Not directly, but they are not truly private.
What are getters and setters?
Allow for updated interdependent attributes
Explain the @property decorator (implement it in code)
Properties are calculated when accessed, meaning you can update dependent attributes.