SlideShare a Scribd company logo
Advance Python
Day 3
CHA PLADIN
cpladin@ibex.co | cpladin@ama.edu
AGENDA
Classes
Inheritance
Polymorphism
QUICK
RECAP
● Python Fundamentals
● Operations
● Data Types
● Lists
● Built-in Function and Methods
● File Built-in Functions
● Loop constructs
● Functions
ACTIVITY - OLD SCHOOLYARD PICK
Write a program that will ask the user for
5 names. Using string manipulations, trim
each name which separates the first
name with the last name and store the
trimmed strings to two lists fname and
lname respectively.
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
__init__() Function
This function is automatically called every
time the class is being used to create a new
object.
__init__() Function
Methods
All functions
that belongs
to a class.
Methods
self parameter
self parameter is a reference to the class
itself, and is used to access variables that
belongs to the class.
self parameter(cont.)
self parameter is not limited to ‘self’ keyword.
Any keyword* would work guided that it has to
be the first parameter of the __init__ method.
Customizing ‘self’ parameter
Instead of using
keyword ‘self’, modify
our Person class by
replacing self by other
keywords and test if
code will still work.
Test it out
Class variables vs Instance variables
Class variable is 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 while
Instance variable is a variable that is defined inside a
method and belongs only to the current instance of a
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.
Accessing attributes
You access the object's attributes using the dot
operator with object.
ACTIVITY - BREAK A LEG
Create a class named Animal having a animal name, animal
color and legs_count. In the same class, create a method
called identify_animal in which you will determine if an
animals is either 2-legged, 4 -legged or limbless or no legs.
If legs_count = 8, it should print out “arthropods”
If legs_count = 4, it should print out “quadruped”
If legs_count = 2, it should print out “biped”
If legs_count = 0, it should print out “apoda”
For other values for legs_count = it should print out “Odd creature”
ACTIVITY - BREAK A LEG
Sample Output
Inheritance
creating a class by deriving it from a
preexisting class by listing the parent
class in parentheses after the new
class name.
Inheritance
Advance Python - Day 3
Activity - Super Idol
Create a parent class called Worker which has instance
variables such as name, email_address and class
variable basic_pay.
Create a subclass CEO which will inherit the name,
email_address and class variable basic_pay. Do a
validation check in your child method that if the inherited
value of basic pay is less than 15,000, you should add
5,000 to the basic pay.
Polymorphism
Different object forms accessing the
same method on both classes.

More Related Content

What's hot (20)

PPTX
Python training
Kunalchauhan76
 
PDF
Python interview questions
Pragati Singh
 
PPTX
Introduction to Python programming Language
MansiSuthar3
 
PPTX
Python Tutorial Part 1
Haitham El-Ghareeb
 
PPTX
Python ppt
Rachit Bhargava
 
PPTX
Fundamentals of Python Programming
Kamal Acharya
 
PDF
Python Interview Questions And Answers
H2Kinfosys
 
PPTX
Introduction to Python for Data Science and Machine Learning
ParrotAI
 
PDF
Python cheat-sheet
srinivasanr281952
 
PDF
Introduction To Programming with Python
Sushant Mane
 
PPTX
Python basics
Jyoti shukla
 
PDF
Overview of python 2019
Samir Mohanty
 
PPTX
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Maulik Borsaniya
 
ODP
Python_in_Detail
MAHALAKSHMI P
 
ODP
Python Presentation
Narendra Sisodiya
 
PPTX
Intro to Python Programming Language
Dipankar Achinta
 
PDF
Python Foundation – A programmer's introduction to Python concepts & style
Kevlin Henney
 
PDF
Introduction to Python Pandas for Data Analytics
Phoenix
 
DOCX
Python Interview Questions For Freshers
zynofustechnology
 
PDF
Introduction to python
Yi-Fan Chu
 
Python training
Kunalchauhan76
 
Python interview questions
Pragati Singh
 
Introduction to Python programming Language
MansiSuthar3
 
Python Tutorial Part 1
Haitham El-Ghareeb
 
Python ppt
Rachit Bhargava
 
Fundamentals of Python Programming
Kamal Acharya
 
Python Interview Questions And Answers
H2Kinfosys
 
Introduction to Python for Data Science and Machine Learning
ParrotAI
 
Python cheat-sheet
srinivasanr281952
 
Introduction To Programming with Python
Sushant Mane
 
Python basics
Jyoti shukla
 
Overview of python 2019
Samir Mohanty
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Maulik Borsaniya
 
Python_in_Detail
MAHALAKSHMI P
 
Python Presentation
Narendra Sisodiya
 
Intro to Python Programming Language
Dipankar Achinta
 
Python Foundation – A programmer's introduction to Python concepts & style
Kevlin Henney
 
Introduction to Python Pandas for Data Analytics
Phoenix
 
Python Interview Questions For Freshers
zynofustechnology
 
Introduction to python
Yi-Fan Chu
 

Similar to Ground Gurus - Python Code Camp - Day 3 - Classes (20)

PPTX
Object oriented Programming concepts explained(3).pptx
grad25iconinfocus
 
PPTX
Module-5-Classes and Objects for Python Programming.pptx
YogeshKumarKJMIT
 
PPTX
Python Lecture 13
Inzamam Baig
 
PPTX
Python programming computer science and engineering
IRAH34
 
PPT
Python3
Ruchika Sinha
 
PPT
Introduction to Python - Part Three
amiable_indian
 
PPTX
Python advance
Mukul Kirti Verma
 
PDF
Unit 3-Classes ,Objects and Inheritance.pdf
Harsha Patil
 
PPTX
IPP-M5-C1-Classes _ Objects python -S2.pptx
DhavalaShreeBJain
 
PDF
python note.pdf
Nagendra504676
 
PPTX
Object oriented Programming in Python.pptx
SHAIKIRFAN715544
 
PPTX
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
NagarathnaRajur2
 
PPTX
2_Classes.pptxjdhfhdfohfshfklsfskkfsdklsdk
thuy27042005thieu
 
PPT
Lecture topic - Python class lecture.ppt
Reji K Dhaman
 
PPT
Lecture on Python class -lecture123456.ppt
Reji K Dhaman
 
PPT
Chap 3 Python Object Oriented Programming - Copy.ppt
muneshwarbisen1
 
PDF
Object oriented Programning Lanuagues in text format.
SravaniSravani53
 
PPTX
Object Oriented Programming.pptx
SAICHARANREDDYN
 
PDF
Object_Oriented_Programming_Unit3.pdf
Koteswari Kasireddy
 
PPTX
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
drkangurajuphd
 
Object oriented Programming concepts explained(3).pptx
grad25iconinfocus
 
Module-5-Classes and Objects for Python Programming.pptx
YogeshKumarKJMIT
 
Python Lecture 13
Inzamam Baig
 
Python programming computer science and engineering
IRAH34
 
Python3
Ruchika Sinha
 
Introduction to Python - Part Three
amiable_indian
 
Python advance
Mukul Kirti Verma
 
Unit 3-Classes ,Objects and Inheritance.pdf
Harsha Patil
 
IPP-M5-C1-Classes _ Objects python -S2.pptx
DhavalaShreeBJain
 
python note.pdf
Nagendra504676
 
Object oriented Programming in Python.pptx
SHAIKIRFAN715544
 
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
NagarathnaRajur2
 
2_Classes.pptxjdhfhdfohfshfklsfskkfsdklsdk
thuy27042005thieu
 
Lecture topic - Python class lecture.ppt
Reji K Dhaman
 
Lecture on Python class -lecture123456.ppt
Reji K Dhaman
 
Chap 3 Python Object Oriented Programming - Copy.ppt
muneshwarbisen1
 
Object oriented Programning Lanuagues in text format.
SravaniSravani53
 
Object Oriented Programming.pptx
SAICHARANREDDYN
 
Object_Oriented_Programming_Unit3.pdf
Koteswari Kasireddy
 
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
drkangurajuphd
 
Ad

More from Chariza Pladin (9)

PDF
Day 4 - Advance Python - Ground Gurus
Chariza Pladin
 
PDF
AI - The Good, Bad and scary truth of Super Intelligence
Chariza Pladin
 
PDF
Computer vision and Open CV
Chariza Pladin
 
PDF
Ground Gurus Introduction
Chariza Pladin
 
PDF
Intro to Web Development Using Python and Django
Chariza Pladin
 
PDF
Data Analysis and Visualization using Python
Chariza Pladin
 
PDF
Game Development With Python and Pygame
Chariza Pladin
 
PDF
Top Libraries for Machine Learning with Python
Chariza Pladin
 
PDF
Introduction to Machine learning with Python
Chariza Pladin
 
Day 4 - Advance Python - Ground Gurus
Chariza Pladin
 
AI - The Good, Bad and scary truth of Super Intelligence
Chariza Pladin
 
Computer vision and Open CV
Chariza Pladin
 
Ground Gurus Introduction
Chariza Pladin
 
Intro to Web Development Using Python and Django
Chariza Pladin
 
Data Analysis and Visualization using Python
Chariza Pladin
 
Game Development With Python and Pygame
Chariza Pladin
 
Top Libraries for Machine Learning with Python
Chariza Pladin
 
Introduction to Machine learning with Python
Chariza Pladin
 
Ad

Recently uploaded (20)

PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
epi editorial commitee meeting presentation
MIPLM
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 

Ground Gurus - Python Code Camp - Day 3 - Classes

  • 3. QUICK RECAP ● Python Fundamentals ● Operations ● Data Types ● Lists ● Built-in Function and Methods ● File Built-in Functions ● Loop constructs ● Functions
  • 4. ACTIVITY - OLD SCHOOLYARD PICK Write a program that will ask the user for 5 names. Using string manipulations, trim each name which separates the first name with the last name and store the trimmed strings to two lists fname and lname respectively.
  • 5. 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.
  • 7. __init__() Function This function is automatically called every time the class is being used to create a new object.
  • 11. self parameter self parameter is a reference to the class itself, and is used to access variables that belongs to the class.
  • 12. self parameter(cont.) self parameter is not limited to ‘self’ keyword. Any keyword* would work guided that it has to be the first parameter of the __init__ method.
  • 14. Instead of using keyword ‘self’, modify our Person class by replacing self by other keywords and test if code will still work. Test it out
  • 15. Class variables vs Instance variables Class variable is 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 while Instance variable is a variable that is defined inside a method and belongs only to the current instance of a class.
  • 16. 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.
  • 17. Accessing attributes You access the object's attributes using the dot operator with object.
  • 18. ACTIVITY - BREAK A LEG Create a class named Animal having a animal name, animal color and legs_count. In the same class, create a method called identify_animal in which you will determine if an animals is either 2-legged, 4 -legged or limbless or no legs. If legs_count = 8, it should print out “arthropods” If legs_count = 4, it should print out “quadruped” If legs_count = 2, it should print out “biped” If legs_count = 0, it should print out “apoda” For other values for legs_count = it should print out “Odd creature”
  • 19. ACTIVITY - BREAK A LEG Sample Output
  • 20. Inheritance creating a class by deriving it from a preexisting class by listing the parent class in parentheses after the new class name.
  • 22. Activity - Super Idol Create a parent class called Worker which has instance variables such as name, email_address and class variable basic_pay. Create a subclass CEO which will inherit the name, email_address and class variable basic_pay. Do a validation check in your child method that if the inherited value of basic pay is less than 15,000, you should add 5,000 to the basic pay.
  • 23. Polymorphism Different object forms accessing the same method on both classes.