Python_OOP
Python_OOP
(OOP)
concepts in Python
What is Object-Oriented Programming in Python?
In Python, a Class is like an object constructor for creating objects.. Each class defines a type and describes the
attributes (data) and methods (functions) that every object created from that class will have.
Every value we create in Python is an object of some class, even basic data types like strings, numbers, and lists.
5
__str__() method
Python's __str__() method defines how a class object is represented as a string. It provides a human-readable
description, useful for logging and debugging.
3. Inheritance in Python
Inheritance allows a class to inherit attributes and methods from another class, promoting code reuse.
The child class can extend the parent's functionality. The super() function helps the child class (e.g., Motorcycle)
access methods and properties of the parent class (e.g., Cars).
Exercices: Python Inheritance
Task 1: Create a class named Student that will inherit properties and methods from a class named Person
Task 2: We have used the Student class to create an object named x. What is the correct syntax to
execute the printname method of the object x?
4. Polymorphism in Python
5. Encapsulation in Python