Code. Models. Analysis. Decisions.

Introduction to Object Oriented Programming in Python

Make a Class in Python

In this video series you will learn how to make and use classes to create objects in your Python applications. You will learn the fundamentals of object-oriented programming, also referred to as OOP, in Python and how to work with classes and objects.

You may have heard that everything in Python is an object. These objects are built from classes much as a house would be built from blueprints. Generally, to "build" an object in Python we usually execute a single line of code such as nums = list(1,2,3). Since the list class (and every other common class) is loaded automatically when you run Python, the language knows what to do. This is sometimes referred to as object-based programming

What we are interested in this series how to define custom classes and build objects from them. Sometimes referred to as object oriented programming, and much like what was described as object based programming above, when we make custom classes, we hide the implementation, or at least we keep it separate from the main Python application. This technique is known as encapsulation - you don't necessarily need to know how a behavior is implemented, just how to use it. Objects generally have data and behavior. Think about lists or strings. The values they hold are their data and the things they can do like sorting or replacing for example are the behaviors we get without worrying about how these methods are implemented. Hiding implementation is often referred to as encapsulation.

Classes can generally be defined as new data types with special behaviors, and often are modeled after real world things. Think Users or Cards or Building. In this series we start with a simple class definition to define a genaric User, and progress through various representations of objects created with the class to adding properties with Python decorators and finish up with inheritance, encapsulation and documentation.

This series is offered free and will get you up and running with Python classes in less than an hour. Familiarity with Python programming is assumed.

Python Object Oriented Programming Tutorials

Working versions of the modules created can be downloaded from github.

Making a Class in Python

Overriding __str__ and __repr__

Adding Methods to Classes

@property Decorator

Inheritance & Encapsulation