0% found this document useful (0 votes)
4 views

Lecture 12 Classes and Objects

The document discusses object-oriented programming in Python, focusing on classes, objects, and inheritance. It explains that a class serves as a blueprint for creating objects, which are instances of classes with specific attribute values. Additionally, it covers how classes can inherit attributes and methods from existing classes, allowing for the creation of child classes that can have multiple parent classes.

Uploaded by

Gareth Matina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture 12 Classes and Objects

The document discusses object-oriented programming in Python, focusing on classes, objects, and inheritance. It explains that a class serves as a blueprint for creating objects, which are instances of classes with specific attribute values. Additionally, it covers how classes can inherit attributes and methods from existing classes, allowing for the creation of child classes that can have multiple parent classes.

Uploaded by

Gareth Matina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Lecture 12: Classes and Objects

Eng. Emanuel Rashayi


Faculty of Engineering, Dept of Electrical & Electronics Engineering , University of Zimbabwe
[email protected]
Python 3 Classes - Objects
➢ Apart from what we've seen until now, Python also has an object-oriented approach.
➢ Up to this point, we have seen one way of programming in Python, using functions
➢ Object-oriented programming is based on classes, methods and objects
➢ In short, a class is a data type containing its own variables, attributes and functions
(which, by the way, in object-oriented programming are called methods).
➢ A standard definition of a class would tell you that a class is like a blueprint for
creating objects.
➢ An object may be regarded as an instance of a defined class and the attribute values
for a particular object define the state of that object.
➢ Another term that is very much used when discussing classes is inheritance.
➢ This means that a new class may inherit all the names and functionalities from an
existing class.
Python 3 Classes - Objects
Python 3 Classes - Objects
Now, let's create our first object
Python 3 Classes - Objects
Python 3 Classes - Objects
Python 3 Classes - Inheritance
➢ We can also create a class that inherits the attributes and methods from an already
existing class.
➢ This is called class inheritance.
➢ In this case, the class inheriting the attributes and methods is called a child and the
class the child inherits from is called - a parent.
➢ To tell Python that you want to inherit from a certain class, you should type in the
parent's name in between parentheses, instead of object, when you define the child
Python 3 Classes - Inheritance
Python 3 Classes - Inheritance

➢ A child class can inherit from two or multiple parents at the same time; the
difference is that when you define the child class, you should enter all the parents
in between parentheses:

class ChildClass(Parent1, Parent2, Parent3):

You might also like