SlideShare a Scribd company logo
1 of 12
Unit 11.4A: Object
Oriented
Programming (OOP)
CLASSES
Programming
11 grade
Learning
objectives:
Unit 11.4A: Object
Oriented
Programming
(OOP)
• 11.4.1.1 create classes and
instances of classes
• 11.4.1.2 develop methods
for the class
Introduction to Classes
https://realpython.com/lessons/classes-
python/
Let’s discuss:
why do we use Classes?
Model: A
Color: orange
Price: 10k
Objects
Class: Car
Model: B
Color: blue
Price: 25k
Car
Model:
Color:
Price:
Drive
Park
Start
Stop
State
Behaviors
Methods(a.k.a
functions)
Attributes
(a.k.a variables)
The class is a user-defined data structure that binds the
data members and methods into a single unit. Class is
a blueprint or code template for object creation. Using a
class, you can create as many objects as you want.
An object is an instance of a class. It is a collection of
attributes (variables) and methods. We use the object of
a class to perform actions.
Define
a class
Classes have methods and attributes
In Python, creating a method defines a class behavior. The word method is the OOP name given to a
function that is defined within a class. To sum up:
• Class functions is synonym for methods
• Class variables is synonym for name attributes
• Type – indicates the class the instance belongs to
• Attribute – Any object value: object.attribute
• Method – a “callable attribute” defined in the class
Declaring a class:
class name:
statements
The following code shows how to create our first class and
then its instance.
class Car:
def __init__(self, model, color, price, fuel_type):
# data members (instance variables)
self.model = model
self.color = color
self.price = price
self.fuel_type = fuel_type
# Behavior (instance methods)
def show(self):
print(‘Model:', self.model, ‘Color:', self.color, ‘Price:', self.price)
# Behavior (instance methods)
def get_fuel_type(self):
print(self.model, ‘run on a', self.fuel_type)
# create object of a class
a = Car(‘A', ‘orange', ‘10k’, ‘Gasoline’)
# call methods
a.show()
a. get_fuel_type()
Use class to
define classes
Python uses class to create objects.
Every defined class has a special
method called __init__(), which allows
you to control how objects are initialized.
Methods within your class are defined in
much the same way as functions, that
is, using def. Here’s the basic form:
The 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 (keyword is
equivalent to “this” in C#/Java).
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:
The importance of self
This is a very important argument assignment.
Without it, the Python interpreter can’t work out which object instance to apply
the method invocation to.
Note that the class code is designed to be shared among all of the object
instances: the methods are shared, the attributes are not. The self argument
helps identify which object instance’s data to work on.
References:
• Python Object-Oriented Programming (OOP) – Pynative
• Python Classes (w3schools.com)
• Head First Python (bedford-computing.co.uk)
• https://realpython.com/lessons/classes-python/
• https://www.youtube.com/watch?v=8yjkWGRlUmY&t=0s
• Изучаем программирование на Python ( PDFDrive ).pdf

More Related Content

Similar to Classes_python.pptx

Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 

Similar to Classes_python.pptx (20)

Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdfPython Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
 
Pythonclass
PythonclassPythonclass
Pythonclass
 
05 ruby classes
05 ruby classes05 ruby classes
05 ruby classes
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptx
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
ABAP Object oriented concepts
ABAP Object oriented conceptsABAP Object oriented concepts
ABAP Object oriented concepts
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP
 
Lecture 2 classes i
Lecture 2 classes iLecture 2 classes i
Lecture 2 classes i
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
creating objects and Class methods
creating objects and Class methodscreating objects and Class methods
creating objects and Class methods
 
Class methods
Class methodsClass methods
Class methods
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Recently uploaded (20)

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

Classes_python.pptx

  • 1. Unit 11.4A: Object Oriented Programming (OOP) CLASSES Programming 11 grade
  • 2. Learning objectives: Unit 11.4A: Object Oriented Programming (OOP) • 11.4.1.1 create classes and instances of classes • 11.4.1.2 develop methods for the class
  • 4. Model: A Color: orange Price: 10k Objects Class: Car Model: B Color: blue Price: 25k Car Model: Color: Price: Drive Park Start Stop State Behaviors Methods(a.k.a functions) Attributes (a.k.a variables)
  • 5. The class is a user-defined data structure that binds the data members and methods into a single unit. Class is a blueprint or code template for object creation. Using a class, you can create as many objects as you want. An object is an instance of a class. It is a collection of attributes (variables) and methods. We use the object of a class to perform actions. Define a class
  • 6. Classes have methods and attributes In Python, creating a method defines a class behavior. The word method is the OOP name given to a function that is defined within a class. To sum up: • Class functions is synonym for methods • Class variables is synonym for name attributes • Type – indicates the class the instance belongs to • Attribute – Any object value: object.attribute • Method – a “callable attribute” defined in the class
  • 7. Declaring a class: class name: statements
  • 8. The following code shows how to create our first class and then its instance. class Car: def __init__(self, model, color, price, fuel_type): # data members (instance variables) self.model = model self.color = color self.price = price self.fuel_type = fuel_type # Behavior (instance methods) def show(self): print(‘Model:', self.model, ‘Color:', self.color, ‘Price:', self.price) # Behavior (instance methods) def get_fuel_type(self): print(self.model, ‘run on a', self.fuel_type) # create object of a class a = Car(‘A', ‘orange', ‘10k’, ‘Gasoline’) # call methods a.show() a. get_fuel_type()
  • 9. Use class to define classes Python uses class to create objects. Every defined class has a special method called __init__(), which allows you to control how objects are initialized. Methods within your class are defined in much the same way as functions, that is, using def. Here’s the basic form:
  • 10. The 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 (keyword is equivalent to “this” in C#/Java). 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:
  • 11. The importance of self This is a very important argument assignment. Without it, the Python interpreter can’t work out which object instance to apply the method invocation to. Note that the class code is designed to be shared among all of the object instances: the methods are shared, the attributes are not. The self argument helps identify which object instance’s data to work on.
  • 12. References: • Python Object-Oriented Programming (OOP) – Pynative • Python Classes (w3schools.com) • Head First Python (bedford-computing.co.uk) • https://realpython.com/lessons/classes-python/ • https://www.youtube.com/watch?v=8yjkWGRlUmY&t=0s • Изучаем программирование на Python ( PDFDrive ).pdf