SlideShare a Scribd company logo
OBJECT
ORIENTED
PROGRAMMMING
Introduction
• Python is an object-oriented programming language. This means
that almost all the code is implemented using a special construct
called classes.
• Python offers classes, which are a effective tool for writing reusable
code. To describe objects with shared characteristics and behaviors,
classes are utilized.
Class
• A class is a user-defined data type that contains both the data
itself and the methods that may be used to manipulate it.
• In a sense, classes serve as a template to create objects. They
provide the characteristics and operations that the objects will
employ.
Object
• An object is an instance of a class. We use the object of a class to
perform actions.
• Objects have two characteristics: They have states and behaviors
(object has attributes and methods attached to it) Attributes
represent its state, and methods represent its behavior.
basic concepts of object oriented in python
Syntax for Class
class class_name:
class
attributes/members
class methods
Syntax for object
object_name = Class_Name(arguments)
OR
object_name = Class_Name()
Example
Class name
Method
Attribute
Call parameter
using Class name
Example
object name
Method
Attribute
Call parameter
using object
Class name
Important Note
• Class attributes are always public and can be accessed using
the dot (.) operator and object name.
• Class methods must have an extra first parameter in the
method definition. We do not give a value for this parameter
when we call the method, Python provides it.
Self parameter
• The self parameter is a reference to the current instance of the
class, and is used to access variables that belongs to the class.
• It does not have to be named self , you can call it whatever you
like, but it has to be the first parameter of any function in the
class.
Class Method
• classmethod() methods are bound to a class rather than an
object. Class methods can be called by both class and object.
These methods can be called with a class or with an object.
Constructor¶
• In object-oriented programming, A constructor is a special method used
to create and initialize an object of a class.
• This method is defined in the class.
• The constructor is executed automatically at the time of object creation.
• The method the __init__() simulates the constructor of the class.
Syntax for constructor
Rules for constructor
• For a class, it allows only one constructor.
• The constructor name must be __init__.
• A constructor must be defined with an instance attribute (nothing but specifying
the self keyword as a first parameter).
• It cannot return any value, except None.
Types of constructor
Default constructor:
 Python will provide a default constructor if no constructor is defined. It does not perform
any task but initializes the objects. It is an empty constructor without a body. This
constructor is known as the default constructor.
 The default constructor is a simple constructor which doesn’t accept any arguments. Its
definition has only one argument which is a reference to the instance being constructed.
Types of constructor
Parameterized constructor:
Constructor with parameters is known as parameterized constructor. The
parameterized constructor takes its first argument as a reference to the instance being
constructed known as self and the rest of the arguments are provided by the
programmer.
Types of constructor
Non-Parameterized constructor:
 A constructor without any arguments is called a non-parameterized constructor.
This type of constructor is used to initialize each object with default values.
 This constructor doesn’t accept the arguments during object creation. Instead, it
initializes every object with the same set of values.
Constructor With Default Values
• Python allows us to define a constructor with default values.
The default value will be used if we do not pass arguments to
the constructor at the time of object creation.
Benefits of constructor
• Initialization of objects
• Easy to implement
• Better readability
• Encapsulation
Disadvantages of constructor
• Overloading not supported: This means that you cannot have
multiple constructors with different parameters in a single class.
• Limited functionality: Python does not have constructors with
access modifiers like public, private or protected.
Destructor
 Destructor is a special method that is called when an object gets destroyed. On
the other hand, a constructor is used to create and initialize an object of a
class.
 The __del__() method is a known as a destructor method in Python.
 In Python, destructors are not needed as much as in C++ because Python has a
garbage collector that handles memory management automatically.
Syntax for Destructor
ENCAPSULATION
▶Encapsulation is one of the fundamental concepts in OOP.
▶It describes the idea of wrapping data and the methods that work on
data within one unit.
▶This puts restrictions on accessing variables and methods directly and
can prevent the modification of data.
▶Using encapsulation,we can hide an object’s internal representation
from outside.This is called information hiding.
ACCESS MODIFIERS IN PYTHON
Encapsulation can be achieved by declaring the data members and
methods of a class either as private or protected.
Private Member
• To define a private variable add two underscores as a prefix at
start of a variable name.
• Private members are accessible only within the class and we can’t
access them directly from the class objects.
Protected Member
▶ Protected members are accessible within the class and also
available to its sub-classes.
▶ To define a protected member,prefix the member name with a
single underscore _.

More Related Content

PPTX
Unit – V Object Oriented Programming in Python.pptx
YugandharaNalavade
 
PPTX
classes and objects of python object oriented
VineelaThonduri
 
PPTX
Object Oriented Programming in Python.pptx
grpvasundhara1993
 
PPTX
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
drkangurajuphd
 
PPTX
مقدمة بايثون .pptx
AlmutasemBillahAlwas
 
PPTX
Python-Classes.pptx
Karudaiyar Ganapathy
 
PPTX
oogshsvshsbhshhshvsvshsvsvhshshjshshhsvgps.pptx
BhojarajTheking
 
Unit – V Object Oriented Programming in Python.pptx
YugandharaNalavade
 
classes and objects of python object oriented
VineelaThonduri
 
Object Oriented Programming in Python.pptx
grpvasundhara1993
 
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
drkangurajuphd
 
مقدمة بايثون .pptx
AlmutasemBillahAlwas
 
Python-Classes.pptx
Karudaiyar Ganapathy
 
oogshsvshsbhshhshvsvshsvsvhshshjshshhsvgps.pptx
BhojarajTheking
 

Similar to basic concepts of object oriented in python (20)

PDF
Object-Oriented Programming System presentation
PavanKumarPathipati
 
PPTX
object oriented porgramming using Java programming
afsheenfaiq2
 
PPTX
Object Oriented Programming.pptx
SAICHARANREDDYN
 
PPTX
software construction and development week 3 Python lists, tuples, dictionari...
MuhammadBilalAjmal2
 
PDF
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Mohammad Reza Kamalifard
 
PPTX
IPP-M5-C1-Classes _ Objects python -S2.pptx
DhavalaShreeBJain
 
PPT
Introduction to Python - Part Three
amiable_indian
 
PPTX
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
NagarathnaRajur2
 
PPTX
Regex,functions, inheritance,class, attribute,overloding
sangumanikesh
 
PPTX
OOPS 46 slide Python concepts .pptx
mrsam3062
 
PPTX
Python 2. classes- cruciql for students objects1.pptx
KiranRaj648995
 
PDF
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
Mohammad Reza Kamalifard
 
PPT
Python3
Ruchika Sinha
 
PPTX
Classes & Objects _
swati463221
 
PPTX
Python – Object Oriented Programming
Raghunath A
 
PDF
Unit 3-Classes ,Objects and Inheritance.pdf
Harsha Patil
 
PPTX
slides11-objects_and_classes in python.pptx
debasisdas225831
 
PPTX
Chapter 05 classes and objects
Praveen M Jigajinni
 
PDF
Lecture 01 - Basic Concept About OOP With Python
National College of Business Administration & Economics ( NCBA&E)
 
Object-Oriented Programming System presentation
PavanKumarPathipati
 
object oriented porgramming using Java programming
afsheenfaiq2
 
Object Oriented Programming.pptx
SAICHARANREDDYN
 
software construction and development week 3 Python lists, tuples, dictionari...
MuhammadBilalAjmal2
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Mohammad Reza Kamalifard
 
IPP-M5-C1-Classes _ Objects python -S2.pptx
DhavalaShreeBJain
 
Introduction to Python - Part Three
amiable_indian
 
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
NagarathnaRajur2
 
Regex,functions, inheritance,class, attribute,overloding
sangumanikesh
 
OOPS 46 slide Python concepts .pptx
mrsam3062
 
Python 2. classes- cruciql for students objects1.pptx
KiranRaj648995
 
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
Mohammad Reza Kamalifard
 
Python3
Ruchika Sinha
 
Classes & Objects _
swati463221
 
Python – Object Oriented Programming
Raghunath A
 
Unit 3-Classes ,Objects and Inheritance.pdf
Harsha Patil
 
slides11-objects_and_classes in python.pptx
debasisdas225831
 
Chapter 05 classes and objects
Praveen M Jigajinni
 
Lecture 01 - Basic Concept About OOP With Python
National College of Business Administration & Economics ( NCBA&E)
 
Ad

More from deepalishinkar1 (20)

PPTX
data structure stack appplication in python
deepalishinkar1
 
PPTX
Stack application in infix to prefix expression
deepalishinkar1
 
PPTX
Data Structure Stack operation in python
deepalishinkar1
 
PPTX
steps for template in django for project
deepalishinkar1
 
PDF
Web application on menu card qrcode generator.pdf
deepalishinkar1
 
PPTX
Django model create a table in django web framework
deepalishinkar1
 
PPTX
TO DO APP USING STREAMLIT PYTHON PROJECT
deepalishinkar1
 
PDF
Inheritance and polymorphism oops concepts in python
deepalishinkar1
 
PPTX
DATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGRE
deepalishinkar1
 
PPTX
File Operations in python Read ,Write,binary file etc.
deepalishinkar1
 
PDF
How to create a django project procedure
deepalishinkar1
 
PDF
Virtual environment in python on windows / linux os
deepalishinkar1
 
PPTX
Operators in python
deepalishinkar1
 
PPTX
Data handling in python
deepalishinkar1
 
PDF
Practical approach on numbers system and math module
deepalishinkar1
 
PDF
Demonstration on keyword
deepalishinkar1
 
PPTX
Numbers and math module
deepalishinkar1
 
PPTX
Basic concepts of python
deepalishinkar1
 
PPTX
Introduction to python
deepalishinkar1
 
PDF
Set methods in python
deepalishinkar1
 
data structure stack appplication in python
deepalishinkar1
 
Stack application in infix to prefix expression
deepalishinkar1
 
Data Structure Stack operation in python
deepalishinkar1
 
steps for template in django for project
deepalishinkar1
 
Web application on menu card qrcode generator.pdf
deepalishinkar1
 
Django model create a table in django web framework
deepalishinkar1
 
TO DO APP USING STREAMLIT PYTHON PROJECT
deepalishinkar1
 
Inheritance and polymorphism oops concepts in python
deepalishinkar1
 
DATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGRE
deepalishinkar1
 
File Operations in python Read ,Write,binary file etc.
deepalishinkar1
 
How to create a django project procedure
deepalishinkar1
 
Virtual environment in python on windows / linux os
deepalishinkar1
 
Operators in python
deepalishinkar1
 
Data handling in python
deepalishinkar1
 
Practical approach on numbers system and math module
deepalishinkar1
 
Demonstration on keyword
deepalishinkar1
 
Numbers and math module
deepalishinkar1
 
Basic concepts of python
deepalishinkar1
 
Introduction to python
deepalishinkar1
 
Set methods in python
deepalishinkar1
 
Ad

Recently uploaded (20)

PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PDF
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
Landforms and landscapes data surprise preview
jpinnuck
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 

basic concepts of object oriented in python

  • 2. Introduction • Python is an object-oriented programming language. This means that almost all the code is implemented using a special construct called classes. • Python offers classes, which are a effective tool for writing reusable code. To describe objects with shared characteristics and behaviors, classes are utilized.
  • 3. Class • A class is a user-defined data type that contains both the data itself and the methods that may be used to manipulate it. • In a sense, classes serve as a template to create objects. They provide the characteristics and operations that the objects will employ.
  • 4. Object • An object is an instance of a class. We use the object of a class to perform actions. • Objects have two characteristics: They have states and behaviors (object has attributes and methods attached to it) Attributes represent its state, and methods represent its behavior.
  • 6. Syntax for Class class class_name: class attributes/members class methods
  • 7. Syntax for object object_name = Class_Name(arguments) OR object_name = Class_Name()
  • 10. Important Note • Class attributes are always public and can be accessed using the dot (.) operator and object name. • Class methods must have an extra first parameter in the method definition. We do not give a value for this parameter when we call the method, Python provides it.
  • 11. Self parameter • The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class. • It does not have to be named self , you can call it whatever you like, but it has to be the first parameter of any function in the class.
  • 12. Class Method • classmethod() methods are bound to a class rather than an object. Class methods can be called by both class and object. These methods can be called with a class or with an object.
  • 13. Constructor¶ • In object-oriented programming, A constructor is a special method used to create and initialize an object of a class. • This method is defined in the class. • The constructor is executed automatically at the time of object creation. • The method the __init__() simulates the constructor of the class.
  • 15. Rules for constructor • For a class, it allows only one constructor. • The constructor name must be __init__. • A constructor must be defined with an instance attribute (nothing but specifying the self keyword as a first parameter). • It cannot return any value, except None.
  • 16. Types of constructor Default constructor:  Python will provide a default constructor if no constructor is defined. It does not perform any task but initializes the objects. It is an empty constructor without a body. This constructor is known as the default constructor.  The default constructor is a simple constructor which doesn’t accept any arguments. Its definition has only one argument which is a reference to the instance being constructed.
  • 17. Types of constructor Parameterized constructor: Constructor with parameters is known as parameterized constructor. The parameterized constructor takes its first argument as a reference to the instance being constructed known as self and the rest of the arguments are provided by the programmer.
  • 18. Types of constructor Non-Parameterized constructor:  A constructor without any arguments is called a non-parameterized constructor. This type of constructor is used to initialize each object with default values.  This constructor doesn’t accept the arguments during object creation. Instead, it initializes every object with the same set of values.
  • 19. Constructor With Default Values • Python allows us to define a constructor with default values. The default value will be used if we do not pass arguments to the constructor at the time of object creation.
  • 20. Benefits of constructor • Initialization of objects • Easy to implement • Better readability • Encapsulation
  • 21. Disadvantages of constructor • Overloading not supported: This means that you cannot have multiple constructors with different parameters in a single class. • Limited functionality: Python does not have constructors with access modifiers like public, private or protected.
  • 22. Destructor  Destructor is a special method that is called when an object gets destroyed. On the other hand, a constructor is used to create and initialize an object of a class.  The __del__() method is a known as a destructor method in Python.  In Python, destructors are not needed as much as in C++ because Python has a garbage collector that handles memory management automatically.
  • 24. ENCAPSULATION ▶Encapsulation is one of the fundamental concepts in OOP. ▶It describes the idea of wrapping data and the methods that work on data within one unit. ▶This puts restrictions on accessing variables and methods directly and can prevent the modification of data. ▶Using encapsulation,we can hide an object’s internal representation from outside.This is called information hiding.
  • 25. ACCESS MODIFIERS IN PYTHON Encapsulation can be achieved by declaring the data members and methods of a class either as private or protected.
  • 26. Private Member • To define a private variable add two underscores as a prefix at start of a variable name. • Private members are accessible only within the class and we can’t access them directly from the class objects.
  • 27. Protected Member ▶ Protected members are accessible within the class and also available to its sub-classes. ▶ To define a protected member,prefix the member name with a single underscore _.