SlideShare a Scribd company logo
4
Most read
7
Most read
8
Most read
CREATING CLASS,
THE SELF
VARIABLES
Advanced Python Programming
• Python is an object oriented programming.
• Almost everything in Python is an object, with it’s properties and methods.
• A class is like an object constructor or a ‘blue print’ for creating objects.
In order to create
eiffiel tower we will
need a blueprint of
the tower
• A Python class is like an outline for creating a new object. An object is anything that
you wish to manipulate or change while working through the code.
• In short, a Python class is for defining a particular type of object. Because Python
objects can have both function and data elements, Python classes define what
methods can be used to change the state of an object. They also indicate what
attributes the object can have.
CREATING CLASS
Example : Create a class name MyClass with a
property named x.
◦ Input:
◦ Output:
Now we can use class named MyClass to create an
object.
◦ Input:
◦ Output:
 To create a class use the keyword class:
o To understand the meaning of classes we have to understand the built-in __init__()
function.
o The __init__ function is called every time an object is created from a class.
o Use the __init__() function to assign values to object properties, or other operations
that are necessary to do when the object is being created:
THE __init__() FUNCTION
Example: Create a class named Person, use the __init__() function to
assign values for name and age:
Input: Output:
SELF VARIABLE
• The self variable is used to represent the instance of the class
which is often used in object-oriented programming.
• It works as a reference to the object.
• Python uses the self parameter to refer to instance attributes and
methods of the class.
What is self constructor?
◦ The self variable in Python can also be used to access a variable field within the class definition.
◦ Example:
class Student:
In the example above, self refers to the variable name of the class Student. The variable name is local to the method. While the
method is running, the variable name exists within the class.
THANK YOU
49_Aditi Pawaskar

More Related Content

What's hot (20)

PPT
Python Dictionaries and Sets
Nicole Ryan
 
PPTX
Python decorators
Alex Su
 
PPTX
virtual function
VENNILAV6
 
PPTX
Java static keyword
Ahmed Shawky El-faky
 
PPTX
Types of methods in python
Aravindreddy Mokireddy
 
PDF
Python programming : Inheritance and polymorphism
Emertxe Information Technologies Pvt Ltd
 
PPS
Wrapper class
kamal kotecha
 
PPTX
Templates in c++
Mayank Bhatt
 
PPTX
Python for loop
Aishwarya Deshmukh
 
PPTX
Stack using Array
Sayantan Sur
 
PPT
Python Control structures
Siddique Ibrahim
 
PPTX
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
PPTX
Java- Nested Classes
Prabhdeep Singh
 
PPTX
Standard Template Library
GauravPatil318
 
DOC
Jumping statements
Suneel Dogra
 
ODP
Python Modules
Nitin Reddy Katkam
 
PPTX
Polymorphism in Python
Home
 
PPT
ConsTRUCTION AND DESTRUCTION
Shweta Shah
 
PPT
RECURSION IN C
v_jk
 
Python Dictionaries and Sets
Nicole Ryan
 
Python decorators
Alex Su
 
virtual function
VENNILAV6
 
Java static keyword
Ahmed Shawky El-faky
 
Types of methods in python
Aravindreddy Mokireddy
 
Python programming : Inheritance and polymorphism
Emertxe Information Technologies Pvt Ltd
 
Wrapper class
kamal kotecha
 
Templates in c++
Mayank Bhatt
 
Python for loop
Aishwarya Deshmukh
 
Stack using Array
Sayantan Sur
 
Python Control structures
Siddique Ibrahim
 
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
Java- Nested Classes
Prabhdeep Singh
 
Standard Template Library
GauravPatil318
 
Jumping statements
Suneel Dogra
 
Python Modules
Nitin Reddy Katkam
 
Polymorphism in Python
Home
 
ConsTRUCTION AND DESTRUCTION
Shweta Shah
 
RECURSION IN C
v_jk
 

Similar to Creating class, self variables in Python (20)

PPTX
Object Oriented Programming Class and Objects
rubini8582
 
PPTX
Introduction to Object Oriented Programming in Python.pptx
eduardocehenmu
 
PPTX
Problem solving with python programming OOP's Concept
rohitsharma24121
 
PPTX
IPP-M5-C1-Classes _ Objects python -S2.pptx
DhavalaShreeBJain
 
PPTX
Lesson 13 object and class
MLG College of Learning, Inc
 
PPTX
Object Oriented Programming.pptx
SAICHARANREDDYN
 
PPTX
oop 3.pptx
OsamaMuhammad18
 
PPTX
basic concepts of object oriented in python
deepalishinkar1
 
PPTX
Class_and_Object_with_Example_Python.pptx janbsbznnsbxghzbbshvxnxhnwn
bandiranvitha
 
PDF
Unit 3-Classes ,Objects and Inheritance.pdf
Harsha Patil
 
PPTX
Object Oriented Programming in Python.pptx
grpvasundhara1993
 
PPTX
Definning class.pptx unit 3
thenmozhip8
 
PDF
oopm 2.pdf
jayeshsoni49
 
PPTX
Regex,functions, inheritance,class, attribute,overloding
sangumanikesh
 
PPTX
oogshsvshsbhshhshvsvshsvsvhshshjshshhsvgps.pptx
BhojarajTheking
 
PPTX
Object oriented Programming in Python.pptx
SHAIKIRFAN715544
 
PPTX
Concept of Object-Oriented in C++
Abdullah Jan
 
PPTX
object oriented programing lecture 1
Geophery sanga
 
PPTX
Python programming Concepts (Functions, classes and Oops concept
Lipika Sharma
 
Object Oriented Programming Class and Objects
rubini8582
 
Introduction to Object Oriented Programming in Python.pptx
eduardocehenmu
 
Problem solving with python programming OOP's Concept
rohitsharma24121
 
IPP-M5-C1-Classes _ Objects python -S2.pptx
DhavalaShreeBJain
 
Lesson 13 object and class
MLG College of Learning, Inc
 
Object Oriented Programming.pptx
SAICHARANREDDYN
 
oop 3.pptx
OsamaMuhammad18
 
basic concepts of object oriented in python
deepalishinkar1
 
Class_and_Object_with_Example_Python.pptx janbsbznnsbxghzbbshvxnxhnwn
bandiranvitha
 
Unit 3-Classes ,Objects and Inheritance.pdf
Harsha Patil
 
Object Oriented Programming in Python.pptx
grpvasundhara1993
 
Definning class.pptx unit 3
thenmozhip8
 
oopm 2.pdf
jayeshsoni49
 
Regex,functions, inheritance,class, attribute,overloding
sangumanikesh
 
oogshsvshsbhshhshvsvshsvsvhshshjshshhsvgps.pptx
BhojarajTheking
 
Object oriented Programming in Python.pptx
SHAIKIRFAN715544
 
Concept of Object-Oriented in C++
Abdullah Jan
 
object oriented programing lecture 1
Geophery sanga
 
Python programming Concepts (Functions, classes and Oops concept
Lipika Sharma
 
Ad

Recently uploaded (20)

DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PDF
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPT
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
Design Thinking basics for Engineers.pdf
CMR University
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
Ad

Creating class, self variables in Python

  • 2. • Python is an object oriented programming. • Almost everything in Python is an object, with it’s properties and methods. • A class is like an object constructor or a ‘blue print’ for creating objects. In order to create eiffiel tower we will need a blueprint of the tower
  • 3. • A Python class is like an outline for creating a new object. An object is anything that you wish to manipulate or change while working through the code. • In short, a Python class is for defining a particular type of object. Because Python objects can have both function and data elements, Python classes define what methods can be used to change the state of an object. They also indicate what attributes the object can have.
  • 4. CREATING CLASS Example : Create a class name MyClass with a property named x. ◦ Input: ◦ Output: Now we can use class named MyClass to create an object. ◦ Input: ◦ Output:  To create a class use the keyword class:
  • 5. o To understand the meaning of classes we have to understand the built-in __init__() function. o The __init__ function is called every time an object is created from a class. o Use the __init__() function to assign values to object properties, or other operations that are necessary to do when the object is being created: THE __init__() FUNCTION
  • 6. Example: Create a class named Person, use the __init__() function to assign values for name and age: Input: Output:
  • 7. SELF VARIABLE • The self variable is used to represent the instance of the class which is often used in object-oriented programming. • It works as a reference to the object. • Python uses the self parameter to refer to instance attributes and methods of the class.
  • 8. What is self constructor? ◦ The self variable in Python can also be used to access a variable field within the class definition. ◦ Example: class Student: In the example above, self refers to the variable name of the class Student. The variable name is local to the method. While the method is running, the variable name exists within the class.