Classes in Python
January 20, 2020
In this video, you’ll be introduced to object-oriented programming using Python. You’ll learn classes and objects and how to create and use them in your Python applications.
Following are two examples of classes in Python. The Course class has a constructor (def __init__()
) explicitly defined whereas the Car class doesn’t have a constructor defined. Any class that doesn’t have a constructor explicitly defined will use Python’s default empty constructor.
# Composition example class Course: def __init__(self, cid, title, credits): self._cid = cid self._title = title self._credits = credits class Car: def start_engine(self): print("Starting engine...")
Want to learn more? My recommendations:
Head First Python: A Brain-Friendly Guide
Introduction to Computing and Programming in Python (3rd Edition)