
Object oriented programming organizes code around objects and classes acting as blueprints to create objects with properties and methods. It enables breaking programs into manageable parts and follows dry principle.
Explain inheritance in object oriented programming by showing how a class inherits methods and properties from a parent class, using a grandfather, father, and child analogy.
Explore polymorphism in Python object oriented programming, using a single function name to perform different actions based on input, illustrated by the customer care analogy.
Class Methods In Python
Learn how to use class methods as alternative constructors in Python OOP, converting a string into a student object via a from_str method, parsing name, age, and height.
Multilevel inheritance in Python
If you already know Python basics, then this course is the next step in your Python learning path to becoming a Python programmer.
this course is specially made for beginners, who want to understand what is object-oriented programming in Python.
In Python, object-oriented Programming (OOPs) is a programming paradigm that uses objects and classes in programming. It aims to implement real-world entities like inheritance, polymorphisms, encapsulation, etc. in the programming. The central concept of OOPs is to bind the data and the functions that work on that together as a single unit so that no other part of the code can access this data.
Main Concepts of Object-Oriented Programming (OOPs)
Class
Objects
Polymorphism
Encapsulation
Inheritance
Data Abstraction
Class
A class is a collection of objects. A class contains the blueprints or the prototype from which the objects are being created. It is a logical entity that contains some attributes and methods.
To understand the need for creating a class let’s consider an example, let’s say you wanted to track the number of dogs that may have different attributes like breed, and age. If a list is used, the first element could represent the dog’s breed while the second could represent its age. Let’s suppose there are 100 different dogs, then how would you know which element is supposed to be which? What if you wanted to add other properties to these dogs? This lacks organization and it’s the exact need for classes.
Objects
The object is an entity that has a state and behavior associated with it. It may be any real-world object like a mouse, keyboard, chair, table, pen, etc. Integers, strings, floating-point numbers, even arrays, and dictionaries, are all objects. More specifically, any single integer or any single string is an object. The number 12 is an object, the string “Hello, world” is an object, a list is an object that can hold other objects, and so on. You’ve been using objects all along and may not even realize it.