DEV Community

kster
kster

Posted on • Updated on

Python Classes

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
Enter fullscreen mode Exit fullscreen mode
  1. 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.
  2. 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.
  3. 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.

Top comments (0)