SlideShare a Scribd company logo
Classes and Objects in Python
(OOP)
Detailed Conceptual Overview with
Examples and Diagrams
Introduction to OOP
• OOP (Object-Oriented Programming) is a
paradigm based on the concept of objects.
• Python supports OOP fully with features like
classes, objects, inheritance, etc.
What is a Class?
• A class is a blueprint for creating objects.
• It defines attributes and methods for the
object.
Syntax of Class
• Example:
• class Person:
• def __init__(self, name):
• self.name = name
• def greet(self):
• print(f"Hello, I am {self.name}")
What is an Object?
• An object is an instance of a class.
• It has state (attributes) and behavior
(methods).
• Example:
• p = Person("Alice")
__init__ Method
• The __init__ method is the constructor in
Python.
• It is automatically called when an object is
created.
Attributes and Methods
• Attributes = variables inside a class.
• Methods = functions defined inside a class.
Accessing Attributes
• You can access attributes using dot notation:
• print(p.name)
Calling Methods
• Call methods with object:
• p.greet()
Self Keyword
• 'self' represents the instance of the class.
• Used to access attributes and methods.
Instance vs Class Variables
• Instance variables are unique to each object.
• Class variables are shared among all objects.
Example: Class Variable
• class Student:
• school = "ABC School"
• def __init__(self, name):
• self.name = name
Modifying Attributes
• You can change attribute values like:
• p.name = "Bob"
Deleting Attributes
• Use del keyword:
• del p.name
Private Attributes
• Prefix with double underscore (__):
• self.__age = 25
• Cannot be accessed directly outside the class.
Using Getters and Setters
• Use methods to access private attributes:
• get_age(), set_age()
Object Identity
• Each object has a unique ID (memory
address).
• Use id(obj) to check.
Multiple Objects
• You can create multiple objects from the same
class:
• p1 = Person("Alice")
• p2 = Person("Bob")
Object-Oriented Design
• Group related data and behavior together
using classes.
Advantages of Using Classes
• • Code Reusability
• • Modularity
• • Encapsulation
• • Scalability
Real-Life Analogy
• Class = Blueprint of a House
• Object = Actual built house based on the
blueprint

More Related Content

PPTX
Object oriented Programming in Python.pptx
PPTX
Class_and_Object_with_Example_Python.pptx janbsbznnsbxghzbbshvxnxhnwn
PPT
Deekshith-class and object.ppt bhkkggxbskoavsvvsjjxbxbbdh
PPTX
Python-Classes.pptx
PPTX
Regex,functions, inheritance,class, attribute,overloding
PPTX
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
PPTX
OOP Concepts Python with code refrences.pptx
Object oriented Programming in Python.pptx
Class_and_Object_with_Example_Python.pptx janbsbznnsbxghzbbshvxnxhnwn
Deekshith-class and object.ppt bhkkggxbskoavsvvsjjxbxbbdh
Python-Classes.pptx
Regex,functions, inheritance,class, attribute,overloding
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
OOP Concepts Python with code refrences.pptx

Similar to Classes_and_Objects_in_Pythonoopsconcept.pptx (20)

PPTX
IPP-M5-C1-Classes _ Objects python -S2.pptx
PPTX
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
PDF
Unit 3-Classes ,Objects and Inheritance.pdf
PPTX
OOPS 46 slide Python concepts .pptx
PPTX
PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
PDF
Lecture 01 - Basic Concept About OOP With Python
PPTX
Introduction to OOP_Python_Lecture1.pptx
PPTX
Python Lecture 13
PPTX
object oriented programming(PYTHON)
PPTX
classes and objects of python object oriented
PPTX
Unit – V Object Oriented Programming in Python.pptx
PPTX
Python advance
PPTX
Problem solving with python programming OOP's Concept
PPTX
My Object Oriented.pptx
PPTX
Object Oriented Programming Class and Objects
PPTX
Presentation on Classes In Python Programming language
PPTX
مقدمة بايثون .pptx
PPTX
software construction and development week 3 Python lists, tuples, dictionari...
PDF
Python Programming - Object-Oriented
PPT
07slide.ppt
IPP-M5-C1-Classes _ Objects python -S2.pptx
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
Unit 3-Classes ,Objects and Inheritance.pdf
OOPS 46 slide Python concepts .pptx
PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
Lecture 01 - Basic Concept About OOP With Python
Introduction to OOP_Python_Lecture1.pptx
Python Lecture 13
object oriented programming(PYTHON)
classes and objects of python object oriented
Unit – V Object Oriented Programming in Python.pptx
Python advance
Problem solving with python programming OOP's Concept
My Object Oriented.pptx
Object Oriented Programming Class and Objects
Presentation on Classes In Python Programming language
مقدمة بايثون .pptx
software construction and development week 3 Python lists, tuples, dictionari...
Python Programming - Object-Oriented
07slide.ppt
Ad

Recently uploaded (20)

PPTX
executive branch_no record.pptxsvvsgsggs
PPT
L1-Intro.ppt nhfjkhghjjnnnmkkjhigtyhhjjj
PPTX
Syllabus Computer Six class curriculum s
PPTX
Presentacion compuuuuuuuuuuuuuuuuuuuuuuu
PPTX
kvjhvhjvhjhjhjghjghjgjhgjhgjhgjhgjhgjhgjhgjh
PPTX
making presentation that do no stick.pptx
PPTX
Embedded for Artificial Intelligence 1.pptx
PDF
YKS Chrome Plated Brass Safety Valve Product Catalogue
PPTX
ERP good ERP good ERP good ERP good good ERP good ERP good
PPTX
dhcp concept.pptxfeegrvewfegrgerhtrhtrhredew
PPTX
STEEL- intro-1.pptxhejwjenwnwnenemwmwmwm
PDF
DOC-20250802-WA0013._20250802_161719_0000.pdf
PPTX
udi-benefits-ggggggggfor-healthcare.pptx
PDF
Layer23-Switch.com The Cisco Catalyst 9300 Series is Cisco’s flagship stackab...
PPTX
了解新西兰毕业证(Wintec毕业证书)怀卡托理工学院毕业证存档可查的
PDF
Prescription1 which to be used for periodo
PDF
Chapter -24-By Dr Sajid Ali Ansari 2021.pdf
PPTX
IOT piching HEALTH MONITORING SYSTEM USING ARDUINO123.pptx
PPTX
ATL_Arduino_Complete_Presentation_AI_Visuals.pptx
PPTX
title _yeOPC_Poisoning_Presentation.pptx
executive branch_no record.pptxsvvsgsggs
L1-Intro.ppt nhfjkhghjjnnnmkkjhigtyhhjjj
Syllabus Computer Six class curriculum s
Presentacion compuuuuuuuuuuuuuuuuuuuuuuu
kvjhvhjvhjhjhjghjghjgjhgjhgjhgjhgjhgjhgjhgjh
making presentation that do no stick.pptx
Embedded for Artificial Intelligence 1.pptx
YKS Chrome Plated Brass Safety Valve Product Catalogue
ERP good ERP good ERP good ERP good good ERP good ERP good
dhcp concept.pptxfeegrvewfegrgerhtrhtrhredew
STEEL- intro-1.pptxhejwjenwnwnenemwmwmwm
DOC-20250802-WA0013._20250802_161719_0000.pdf
udi-benefits-ggggggggfor-healthcare.pptx
Layer23-Switch.com The Cisco Catalyst 9300 Series is Cisco’s flagship stackab...
了解新西兰毕业证(Wintec毕业证书)怀卡托理工学院毕业证存档可查的
Prescription1 which to be used for periodo
Chapter -24-By Dr Sajid Ali Ansari 2021.pdf
IOT piching HEALTH MONITORING SYSTEM USING ARDUINO123.pptx
ATL_Arduino_Complete_Presentation_AI_Visuals.pptx
title _yeOPC_Poisoning_Presentation.pptx
Ad

Classes_and_Objects_in_Pythonoopsconcept.pptx