Monthly Archives: October 2017

Object Oriented Programming

In this series, we’ll explore Object Oriented Programming. Everything is an object in Python. Sometimes the terms objects and classes are mixed, but they are different concepts. Related course: Python Beyond the Basics – Object-Oriented Programming Object An object can contain variables and/or methods that interact with those variables. Sometimes objects are named after real […]

Class

In Python everything is an object. An object has zero or more methods. Thus far you have already worked with objects. Let’s take an example:

In the above example, we have an object named s (a list). This object has the methods reverse(), append() and remove(). Related course: Python Beyond the Basics – Object-Oriented […]

Constructor

A constructor is the first method that is called on object creation. The constructor is always called when creating a new object. It can be used to initialize class variables and startup routines. Related course: Complete Python Bootcamp: Go from zero to hero in Python Example In the example below we create a class C […]

Class attributes

A class can have attributes (sometimes called variables). Objects created from a class have all of the parent classes variables. This allows us to do Object Orientated Programming: we speak about (albeit) virtual objects. Those objects can have unique properties. Related course: Python Beyond the Basics – Object-Oriented Programming Attributes example Start with a class […]

Class Methods

Objects can call methods, those methods are defined in classes. Methods can modify all variables of an object. This is done with the self keyword. Because methods can be called from an object (instance), they are sometimes called instance methods. Related course: Python Beyond the Basics – Object-Oriented Programming Example If you have a class […]

Getting started

To get started, you will need the Python interpreter or a Python IDE. An IDE is a tool that will make the experience of software development much better. Related course: Python interpreter You can download Python interpreter here: https://www.python.org/downloads/ The Python interpreter is a command line program, we’ll discuss it in the next lecture. Python […]

Python self

The self parameter is often used in object orientated programming. The self parameter is added inside class methods, but why? It’s a reference to the the object. That may sound vague, so let me explain. Let’s say you have a class Animal with two instances: Cat and Dog. The self keyword now refers to the […]

Inheritance

Inheritance is one of the key concepts of object orientated programming (OOP). Objects are created using classes, but that’s not all. A class can inherit the methods and variables from another class. This principle helps us to avoid duplicate code. In turn, a created object has methods and variables from both classes. Related course: Complete […]

Multiple Inheritance

In Python a class can inherit from more than one class. The resulting class will have all the methods and attributes from the parent classes. In essence, it’s called multiple inheritance because a class can inherit from multiple classes. Related course: Complete Python Bootcamp: Go from zero to hero in Python Example In the example […]

Object Serialization with Pickle

Objects can be serialized: stored in a format for later use. Once an object is serialized, it can be stored in a file and loaded from a file. The pickle module can be used for object serialization. Related course: Python Beyond the Basics – Object-Oriented Programming Create and dump an object We start by creating […]