SlideShare a Scribd company logo
3
Most read
4
Most read
9
Most read
Swipe
Python - Object Oriented
Python has been an object-oriented language
since it existed.
Because of this, creating and using classes and
objects are downright easy.
This chapter helps you become an expert in using
Python's object-oriented programming support.
If you do not have any previous experience with
object-oriented (OO) programming, you may want
to consult an introductory course on it or at least
a tutorial of some sort so that you have a grasp of
the basic concepts.
Python - Object Oriented
Class
A user-defined prototype for an object that
defines a set of attributes that characterize
any object of the class.
The attributes are data members (class
variables and instance variables) and methods,
accessed via dot notation.
Class variable
A variable that is shared by all instances of a
class. Class variables are defined within a class
but outside any of the class's methods. Class
variables are not used as frequently as
instance variables are.
OOP Terminology
Data member
A class variable or instance variable that holds
data associated with a class and its objects.
Function overloading
The assignment of more than one behavior to
a particular function. The operation performed
varies by the types of objects or arguments
involved.
Instance variable
A variable that is defined inside a method and
belongs only to the current instance of a class.
Inheritance
The transfer of the characteristics of a class to
other classes that are derived from it.
Instance
An individual object of a certain class. An
object obj that belongs to a class Circle, for
example, is an instance of the class Circle.
Instantiation
The creation of an instance of a class.
Method
A special kind of function that is defined in a
class definition.
Object
A unique instance of a data structure that's
defined by its class. An object comprises both
data members (class variables and instance
variables) and methods.
Operator overloading
The assignment of more than one function to a
particular operator.
Creating Classes
The class statement creates a new class definition.
The name of the class immediately follows the
keyword class followed by a colon as follows
class ClassName:
'Optional class documentation string'
class_suite
The class has a documentation string, which can
be accessed via ClassName.__doc__.
The class_suite consists of all the component
statements defining class members, data
attributes and functions.
The variable empCount is a class variable whose
value is shared among all instances of a this class.
This can be accessed as Employee.empCount from
inside the class or outside the class.
Creating Instance Objects
To create instances of a class, you call the class
using class name and pass in whatever arguments
its __init__ method accepts.
"This would create first object of Employee class"
emp1 = Employee("Zara", 2000)
"This would create second object of Employee class"
emp2 = Employee("Manni", 5000)
Accessing Attributes
You access the object's attributes using the dot
operator with object. Class variable would be
accessed using class name as follows
emp1.displayEmployee()
emp2.displayEmployee()
print "Total Employee %d" % Employee.empCount
Built-In Class Attributes
Every Python class keeps following built-in
attributes and they can be accessed using dot
operator like any other attribute
__dict__ − Dictionary containing the class's
namespace.
__doc__ − Class documentation string or none, if
undefined.
__name__ − Class name.
__module__ − Module name in which the class is
defined. This attribute is "__main__" in interactive
mode.
__bases__ − A possibly empty tuple containing the
base classes, in the order of their occurrence in
the base class list.
Python - MySQL Database
Access
Python - Network Programming
Stay Tuned with
Topics for next Post

More Related Content

PDF
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PPTX
Object oriented programming in python
PPTX
Object Oriented Programming in Python
PPTX
Object oriented programming with python
PPTX
Class, object and inheritance in python
PPTX
PDF
Python programming : Inheritance and polymorphism
PPTX
Chapter 07 inheritance
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Object oriented programming in python
Object Oriented Programming in Python
Object oriented programming with python
Class, object and inheritance in python
Python programming : Inheritance and polymorphism
Chapter 07 inheritance

What's hot (20)

PDF
Object oriented approach in python programming
PPTX
Polymorphism in java
PPTX
Python OOPs
PDF
Arrays in Java
PDF
Python Class | Python Programming | Python Tutorial | Edureka
PDF
Python programming : Classes objects
PPTX
Object oriented programming in python
PPTX
Super keyword in java
PPT
Python Dictionaries and Sets
PDF
Introduction to NumPy (PyData SV 2013)
PPTX
Data Structures in Python
PPTX
Constructor in java
PPT
Python GUI Programming
PPTX
Polymorphism presentation in java
PPT
Inheritance in java
PDF
Python programming : Files
PDF
Polymorphism in oop
PPTX
Data Types, Variables, and Operators
PPTX
Access specifiers(modifiers) in java
Object oriented approach in python programming
Polymorphism in java
Python OOPs
Arrays in Java
Python Class | Python Programming | Python Tutorial | Edureka
Python programming : Classes objects
Object oriented programming in python
Super keyword in java
Python Dictionaries and Sets
Introduction to NumPy (PyData SV 2013)
Data Structures in Python
Constructor in java
Python GUI Programming
Polymorphism presentation in java
Inheritance in java
Python programming : Files
Polymorphism in oop
Data Types, Variables, and Operators
Access specifiers(modifiers) in java
Ad

Similar to Python - object oriented (20)

PPTX
Python advance
PDF
Lecture 01 - Basic Concept About OOP With Python
PPTX
IPP-M5-C1-Classes _ Objects python -S2.pptx
PPTX
Python-Classes.pptx
PDF
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
PPTX
Object Oriented Programming.pptx
PPTX
ITS-16163: Module 7 Introduction to Object-Oriented Programming Basics
PPTX
Class_and_Object_with_Example_Python.pptx janbsbznnsbxghzbbshvxnxhnwn
PPTX
Object oriented Programming in Python.pptx
PDF
Unit 3-Classes ,Objects and Inheritance.pdf
PPTX
Introduction to OOP in Python
PDF
introductiontooopinpython-171115114144.pdf
PPTX
Classes_and_Objects_in_Pythonoopsconcept.pptx
PPTX
OOP concepts -in-Python programming language
PPTX
Object Oriented Programming Class and Objects
PPTX
object oriented porgramming using Java programming
PPTX
My Object Oriented.pptx
PPTX
Regex,functions, inheritance,class, attribute,overloding
Python advance
Lecture 01 - Basic Concept About OOP With Python
IPP-M5-C1-Classes _ Objects python -S2.pptx
Python-Classes.pptx
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
Object Oriented Programming.pptx
ITS-16163: Module 7 Introduction to Object-Oriented Programming Basics
Class_and_Object_with_Example_Python.pptx janbsbznnsbxghzbbshvxnxhnwn
Object oriented Programming in Python.pptx
Unit 3-Classes ,Objects and Inheritance.pdf
Introduction to OOP in Python
introductiontooopinpython-171115114144.pdf
Classes_and_Objects_in_Pythonoopsconcept.pptx
OOP concepts -in-Python programming language
Object Oriented Programming Class and Objects
object oriented porgramming using Java programming
My Object Oriented.pptx
Regex,functions, inheritance,class, attribute,overloding
Ad

More from Learnbay Datascience (20)

PDF
Top data science projects
PDF
Python my SQL - create table
PDF
Python my SQL - create database
PDF
Python my sql database connection
PDF
Python - mySOL
PDF
AI - Issues and Terminology
PDF
AI - Fuzzy Logic Systems
PDF
AI - working of an ns
PDF
Artificial Intelligence- Neural Networks
PDF
AI - Robotics
PDF
Applications of expert system
PDF
Components of expert systems
PDF
Artificial intelligence - expert systems
PDF
AI - natural language processing
PDF
Ai popular search algorithms
PDF
AI - Agents & Environments
PDF
Artificial intelligence - research areas
PDF
Artificial intelligence composed
PDF
Artificial intelligence intelligent systems
PDF
Applications of ai
Top data science projects
Python my SQL - create table
Python my SQL - create database
Python my sql database connection
Python - mySOL
AI - Issues and Terminology
AI - Fuzzy Logic Systems
AI - working of an ns
Artificial Intelligence- Neural Networks
AI - Robotics
Applications of expert system
Components of expert systems
Artificial intelligence - expert systems
AI - natural language processing
Ai popular search algorithms
AI - Agents & Environments
Artificial intelligence - research areas
Artificial intelligence composed
Artificial intelligence intelligent systems
Applications of ai

Recently uploaded (20)

PDF
Landforms and landscapes data surprise preview
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PPTX
How to Manage Loyalty Points in Odoo 18 Sales
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Types of Literary Text: Poetry and Prose
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PDF
High Ground Student Revision Booklet Preview
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PDF
English Language Teaching from Post-.pdf
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
Landforms and landscapes data surprise preview
O7-L3 Supply Chain Operations - ICLT Program
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
How to Manage Loyalty Points in Odoo 18 Sales
Renaissance Architecture: A Journey from Faith to Humanism
Week 4 Term 3 Study Techniques revisited.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Types of Literary Text: Poetry and Prose
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Module 3: Health Systems Tutorial Slides S2 2025
High Ground Student Revision Booklet Preview
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
Insiders guide to clinical Medicine.pdf
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
human mycosis Human fungal infections are called human mycosis..pptx
The Final Stretch: How to Release a Game and Not Die in the Process.
English Language Teaching from Post-.pdf
How to Manage Starshipit in Odoo 18 - Odoo Slides

Python - object oriented

  • 2. Python has been an object-oriented language since it existed. Because of this, creating and using classes and objects are downright easy. This chapter helps you become an expert in using Python's object-oriented programming support. If you do not have any previous experience with object-oriented (OO) programming, you may want to consult an introductory course on it or at least a tutorial of some sort so that you have a grasp of the basic concepts. Python - Object Oriented
  • 3. Class A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation. Class variable A variable that is shared by all instances of a class. Class variables are defined within a class but outside any of the class's methods. Class variables are not used as frequently as instance variables are. OOP Terminology
  • 4. Data member A class variable or instance variable that holds data associated with a class and its objects. Function overloading The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved. Instance variable A variable that is defined inside a method and belongs only to the current instance of a class. Inheritance The transfer of the characteristics of a class to other classes that are derived from it.
  • 5. Instance An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle. Instantiation The creation of an instance of a class. Method A special kind of function that is defined in a class definition. Object A unique instance of a data structure that's defined by its class. An object comprises both data members (class variables and instance variables) and methods. Operator overloading The assignment of more than one function to a particular operator.
  • 6. Creating Classes The class statement creates a new class definition. The name of the class immediately follows the keyword class followed by a colon as follows class ClassName: 'Optional class documentation string' class_suite The class has a documentation string, which can be accessed via ClassName.__doc__. The class_suite consists of all the component statements defining class members, data attributes and functions. The variable empCount is a class variable whose value is shared among all instances of a this class. This can be accessed as Employee.empCount from inside the class or outside the class.
  • 7. Creating Instance Objects To create instances of a class, you call the class using class name and pass in whatever arguments its __init__ method accepts. "This would create first object of Employee class" emp1 = Employee("Zara", 2000) "This would create second object of Employee class" emp2 = Employee("Manni", 5000)
  • 8. Accessing Attributes You access the object's attributes using the dot operator with object. Class variable would be accessed using class name as follows emp1.displayEmployee() emp2.displayEmployee() print "Total Employee %d" % Employee.empCount
  • 9. Built-In Class Attributes Every Python class keeps following built-in attributes and they can be accessed using dot operator like any other attribute __dict__ − Dictionary containing the class's namespace. __doc__ − Class documentation string or none, if undefined. __name__ − Class name. __module__ − Module name in which the class is defined. This attribute is "__main__" in interactive mode. __bases__ − A possibly empty tuple containing the base classes, in the order of their occurrence in the base class list.
  • 10. Python - MySQL Database Access Python - Network Programming Stay Tuned with Topics for next Post