SlideShare a Scribd company logo
6
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 with python
PPTX
Object Oriented Programming in Python
PPTX
Class, object and inheritance in python
PDF
Python programming : Inheritance and polymorphism
PPTX
Chapter 07 inheritance
PPTX
Introduction to OOP in Python
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Object oriented programming in python
Object oriented programming with python
Object Oriented Programming in Python
Class, object and inheritance in python
Python programming : Inheritance and polymorphism
Chapter 07 inheritance
Introduction to OOP in Python

What's hot (20)

PPTX
Classes objects in java
PPTX
Python-Classes.pptx
PPTX
Polymorphism in java
PPTX
Oop c++class(final).ppt
PDF
Python programming : Classes objects
PPTX
Python oop third class
PPTX
array of object pointer in c++
PPT
Object and class
PPTX
Inheritance in java
PDF
Function arguments In Python
PPTX
Classes and Objects in C#
PPTX
Constructor and Types of Constructors
PPS
Interface
PPTX
Java package
PPTX
[OOP - Lec 19] Static Member Functions
PPT
Operator Overloading
PPSX
Modules and packages in python
PPTX
Types of methods in python
PPTX
Packages in java
PPTX
Python-Polymorphism.pptx
Classes objects in java
Python-Classes.pptx
Polymorphism in java
Oop c++class(final).ppt
Python programming : Classes objects
Python oop third class
array of object pointer in c++
Object and class
Inheritance in java
Function arguments In Python
Classes and Objects in C#
Constructor and Types of Constructors
Interface
Java package
[OOP - Lec 19] Static Member Functions
Operator Overloading
Modules and packages in python
Types of methods in python
Packages in java
Python-Polymorphism.pptx
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
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
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
PPT
Python session 7 by Shan
PPTX
PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
Python advance
Lecture 01 - Basic Concept About OOP With Python
IPP-M5-C1-Classes _ Objects python -S2.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
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
Python session 7 by Shan
PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
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
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Pre independence Education in Inndia.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
Basic Mud Logging Guide for educational purpose
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
TR - Agricultural Crops Production NC III.pdf
Open Quiz Monsoon Mind Game Prelims.pptx
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Renaissance Architecture: A Journey from Faith to Humanism
Pre independence Education in Inndia.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Anesthesia in Laparoscopic Surgery in India
Cardiovascular Pharmacology for pharmacy students.pptx
Basic Mud Logging Guide for educational purpose
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Microbial diseases, their pathogenesis and prophylaxis
human mycosis Human fungal infections are called human mycosis..pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
O7-L3 Supply Chain Operations - ICLT Program
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf

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