213 Creating classes
What naming convention is typically used for class names in Python?
Show solution
Class names in Python typically use camel case, starting with an uppercase letter. For example: LightSwitch.
What does the colon at the end of a class statement indicate in Python?
Show solution
The colon indicates that the body of the class definition follows. It is similar to how colons are used after def, if, for and other Python statements.
Define a method in Python and describe its characteristics.
Show solution
A method is a function defined inside a class. It always has at least one parameter, usually named self, which refers to the specific object calling the method.
What is the purpose of the init method in a class?
Show solution
The __init__ method is a special method that runs automatically whenever a new object is created from a class. It is typically used to initialise the object’s attributes.
Is the
initmethod required in every Python class? Why might you include it anyway?
Last updated
Was this helpful?