1b. Class Basics Flashcards
What keyword is used to define a class?
The “class” keyword is used to define a classing.
When are parentheses required in a class definition?
When the class being defined inherits from another.
What’s the naming convention for classes?
PascalCase
How do you instantiate a class in Python?
By calling the class with parantheses. (eg. classname=Book instantiation=Book())
What does the __init__ method do?
It initialises the new object with information.
Is the __init__ method the constructor of a class?
No. It’s more correct to call it the initialiser, because, internally, the object is already created before calling this method.
When is the __init__ method called for a class?
It is called when the class is instantiated. It runs before any other method can for any given class.
What’s the first argument any non-static class methods take?
It is the class instance. By convention, it is called “self”. However, it can really be called anything.
How do you access an object’s class attributes?
By using dot notation. (eg. book.title)