7.6 Naming conventions and encapsulation
In section 6.3, we covered naming conventions for functions. Let’s complete the story for classes and their contents.
Although many built-in classes like int
and float
have lowercase names, your class names should begin with a capital
letter. If the name has multiple “words”, start those with capital letters as well. Don’t use
underscores. Examples are BreadRecipe
, ElectricGuitar
, and Matrix
.
Instance variables should follow the same naming conventions as other variables, and methods should follow the conventions for functions. All letters should be lowercase, and you may use underscores.
End a name with an underscore to avoid confusion with a Python keyword.
class_ = "Quantum Computing 101"
class_
'Quantum Computing 101'
Magic methods (section 7.4) begin and end with two underscores.
Python does not...