Python Classes

kster

kster

Posted on September 26, 2022

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.
💖 💪 🙅 🚩
kster
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.

Related

Day 2 of python programming 🧡
100daysofcode Day 2 of python programming 🧡

July 12, 2024

Day 1: Python Programming 🧡
100daysofcode Day 1: Python Programming 🧡

July 11, 2024

Lists in Python
python Lists in Python

October 18, 2022

Python Polymorphism
python Python Polymorphism

October 2, 2022