Python Classes
kster
Posted on September 26, 2022
Defining a Class in Python
A class is a blue print of an object. Where the class is the blue print of the house, the object is the actual house built.
Similar to how function definitions begin with a 'def' keyword in Python, class definitions begin with a 'class' keyword.
class MyNewClass:
'''Docstring goes here. I have created a new class'''
pass
- Here we created a class named 'MyNewClass'. Notice we use the CapWords convention since PEP 8 Style Guide for Python Code recommends this for Class names.
- A docstring is not mandatory but highly recommended. It is written so programmers can understand what it does without having to read the details of the implementation.
- The 'pass' keyword is used in Python to indicate that the body of the class was intentionally left blank. This prevents an 'IndentationError' from occurring in the terminal.
💖 💪 🙅 🚩
kster
Posted on September 26, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.