SlideShare a Scribd company logo
1 of 23
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

Python interview questions
Python interview questionsPython interview questions
Python interview questionsPragati Singh
 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming LanguageMansiSuthar3
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python ProgrammingKamal Acharya
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And AnswersH2Kinfosys
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning ParrotAI
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with PythonSushant Mane
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019Samir Mohanty
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAMaulik Borsaniya
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming LanguageDipankar Achinta
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & styleKevlin Henney
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsPhoenix
 
Python Interview Questions For Freshers
Python Interview Questions For FreshersPython Interview Questions For Freshers
Python Interview Questions For Fresherszynofustechnology
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonYi-Fan Chu
 

What's hot (20)

Python training
Python trainingPython training
Python training
 
Python interview questions
Python interview questionsPython interview questions
Python interview questions
 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming Language
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Python ppt
Python pptPython ppt
Python ppt
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
 
Python basics
Python basicsPython basics
Python basics
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
 
Python_in_Detail
Python_in_DetailPython_in_Detail
Python_in_Detail
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & style
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
 
Python Interview Questions For Freshers
Python Interview Questions For FreshersPython Interview Questions For Freshers
Python Interview Questions For Freshers
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 

Similar to Advance Python Day 3 Classes, Inheritance, Polymorphism

اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونیاسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونیMohammad Reza Kamalifard
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲Mohammad Reza Kamalifard
 
Python Classes and Objects part13
Python Classes and Objects  part13Python Classes and Objects  part13
Python Classes and Objects part13Vishal Dutt
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programmingSrinivas Narasegouda
 
Object Oriented Programming.pptx
Object Oriented Programming.pptxObject Oriented Programming.pptx
Object Oriented Programming.pptxSAICHARANREDDYN
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxShaownRoy1
 
PythonOO.pdf oo Object Oriented programming
PythonOO.pdf oo Object Oriented programmingPythonOO.pdf oo Object Oriented programming
PythonOO.pdf oo Object Oriented programmingKhadijaKhadijaAouadi
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programmingNeelesh Shukla
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Threeamiable_indian
 

Similar to Advance Python Day 3 Classes, Inheritance, Polymorphism (20)

Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
 
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونیاسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
 
Pythonclass
PythonclassPythonclass
Pythonclass
 
python note.pdf
python note.pdfpython note.pdf
python note.pdf
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Python Classes and Objects part13
Python Classes and Objects  part13Python Classes and Objects  part13
Python Classes and Objects part13
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
 
Python oop third class
Python oop   third classPython oop   third class
Python oop third class
 
Object Oriented Programming.pptx
Object Oriented Programming.pptxObject Oriented Programming.pptx
Object Oriented Programming.pptx
 
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 
PythonOO.pdf oo Object Oriented programming
PythonOO.pdf oo Object Oriented programmingPythonOO.pdf oo Object Oriented programming
PythonOO.pdf oo Object Oriented programming
 
Python-Classes.pptx
Python-Classes.pptxPython-Classes.pptx
Python-Classes.pptx
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
 
S12.s01 - Material TP.pdf
S12.s01 - Material TP.pdfS12.s01 - Material TP.pdf
S12.s01 - Material TP.pdf
 

More from Chariza Pladin

Day 4 - Advance Python - Ground Gurus
Day 4 - Advance Python - Ground GurusDay 4 - Advance Python - Ground Gurus
Day 4 - Advance Python - Ground GurusChariza Pladin
 
AI - The Good, Bad and scary truth of Super Intelligence
AI - The Good, Bad and scary truth of Super IntelligenceAI - The Good, Bad and scary truth of Super Intelligence
AI - The Good, Bad and scary truth of Super IntelligenceChariza Pladin
 
Computer vision and Open CV
Computer vision and Open CVComputer vision and Open CV
Computer vision and Open CVChariza Pladin
 
Ground Gurus Introduction
Ground Gurus IntroductionGround Gurus Introduction
Ground Gurus IntroductionChariza Pladin
 
Intro to Web Development Using Python and Django
Intro to Web Development Using Python and DjangoIntro to Web Development Using Python and Django
Intro to Web Development Using Python and DjangoChariza Pladin
 
Data Analysis and Visualization using Python
Data Analysis and Visualization using PythonData Analysis and Visualization using Python
Data Analysis and Visualization using PythonChariza Pladin
 
Game Development With Python and Pygame
Game Development With Python and PygameGame Development With Python and Pygame
Game Development With Python and PygameChariza Pladin
 
Top Libraries for Machine Learning with Python
Top Libraries for Machine Learning with Python Top Libraries for Machine Learning with Python
Top Libraries for Machine Learning with Python Chariza Pladin
 
Introduction to Machine learning with Python
Introduction to Machine learning with PythonIntroduction to Machine learning with Python
Introduction to Machine learning with PythonChariza Pladin
 

More from Chariza Pladin (9)

Day 4 - Advance Python - Ground Gurus
Day 4 - Advance Python - Ground GurusDay 4 - Advance Python - Ground Gurus
Day 4 - Advance Python - Ground Gurus
 
AI - The Good, Bad and scary truth of Super Intelligence
AI - The Good, Bad and scary truth of Super IntelligenceAI - The Good, Bad and scary truth of Super Intelligence
AI - The Good, Bad and scary truth of Super Intelligence
 
Computer vision and Open CV
Computer vision and Open CVComputer vision and Open CV
Computer vision and Open CV
 
Ground Gurus Introduction
Ground Gurus IntroductionGround Gurus Introduction
Ground Gurus Introduction
 
Intro to Web Development Using Python and Django
Intro to Web Development Using Python and DjangoIntro to Web Development Using Python and Django
Intro to Web Development Using Python and Django
 
Data Analysis and Visualization using Python
Data Analysis and Visualization using PythonData Analysis and Visualization using Python
Data Analysis and Visualization using Python
 
Game Development With Python and Pygame
Game Development With Python and PygameGame Development With Python and Pygame
Game Development With Python and Pygame
 
Top Libraries for Machine Learning with Python
Top Libraries for Machine Learning with Python Top Libraries for Machine Learning with Python
Top Libraries for Machine Learning with Python
 
Introduction to Machine learning with Python
Introduction to Machine learning with PythonIntroduction to Machine learning with Python
Introduction to Machine learning with Python
 

Recently uploaded

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Recently uploaded (20)

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 

Advance Python Day 3 Classes, Inheritance, Polymorphism

  • 1. Advance Python Day 3 CHA PLADIN cpladin@ibex.co | cpladin@ama.edu
  • 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.