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

PDF
Zero to Hero - Introduction to Python3
PPTX
Introduction to python
PPTX
Python 3 Programming Language
PPT
Introduction to Python
DOCX
Python interview questions
PDF
Most Asked Python Interview Questions
DOCX
Python interview questions and answers
Zero to Hero - Introduction to Python3
Introduction to python
Python 3 Programming Language
Introduction to Python
Python interview questions
Most Asked Python Interview Questions
Python interview questions and answers

What's hot (20)

PPTX
Python training
PDF
Python interview questions
PPTX
Introduction to Python programming Language
PPTX
Python Tutorial Part 1
PPTX
Python ppt
PPTX
Fundamentals of Python Programming
PDF
Python Interview Questions And Answers
PPTX
Introduction to Python for Data Science and Machine Learning
PDF
Python cheat-sheet
PDF
Introduction To Programming with Python
PPTX
Python basics
PDF
Overview of python 2019
PPTX
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
ODP
Python_in_Detail
ODP
Python Presentation
PPTX
Intro to Python Programming Language
PDF
Python Foundation – A programmer's introduction to Python concepts & style
PDF
Introduction to Python Pandas for Data Analytics
DOCX
Python Interview Questions For Freshers
PDF
Introduction to python
Python training
Python interview questions
Introduction to Python programming Language
Python Tutorial Part 1
Python ppt
Fundamentals of Python Programming
Python Interview Questions And Answers
Introduction to Python for Data Science and Machine Learning
Python cheat-sheet
Introduction To Programming with Python
Python basics
Overview of python 2019
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Python_in_Detail
Python Presentation
Intro to Python Programming Language
Python Foundation – A programmer's introduction to Python concepts & style
Introduction to Python Pandas for Data Analytics
Python Interview Questions For Freshers
Introduction to python
Ad

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

PPTX
classes and objects of python object oriented
PDF
Python - object oriented
PPTX
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
PDF
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
PPTX
PYTHON-COURSE-PROGRAMMING-UNIT-IV--.pptx
PPTX
03 object-classes-pbl-4-slots
PPTX
03 object-classes-pbl-4-slots
PDF
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PPTX
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
PPTX
PYTHON OBJECT-ORIENTED PROGRAMMING.pptx
PPTX
Detailed_description_on_java_ppt_final.pptx
PDF
python note.pdf
PPTX
Unit3 part1-class
PPTX
Python Classes and Objects part13
PDF
oblect oriented programming language in java notes .pdf
PPTX
python.pptx
PPTX
Object Oriented Programming in Python.pptx
PDF
Object oriented approach in python programming
PPTX
Python oop third class
classes and objects of python object oriented
Python - object oriented
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
PYTHON-COURSE-PROGRAMMING-UNIT-IV--.pptx
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
PYTHON OBJECT-ORIENTED PROGRAMMING.pptx
Detailed_description_on_java_ppt_final.pptx
python note.pdf
Unit3 part1-class
Python Classes and Objects part13
oblect oriented programming language in java notes .pdf
python.pptx
Object Oriented Programming in Python.pptx
Object oriented approach in python programming
Python oop third class
Ad

More from Chariza Pladin (9)

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

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
RMMM.pdf make it easy to upload and study
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Pre independence Education in Inndia.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
master seminar digital applications in india
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
Final Presentation General Medicine 03-08-2024.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Renaissance Architecture: A Journey from Faith to Humanism
O7-L3 Supply Chain Operations - ICLT Program
RMMM.pdf make it easy to upload and study
Pharma ospi slides which help in ospi learning
Week 4 Term 3 Study Techniques revisited.pptx
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pre independence Education in Inndia.pdf
Institutional Correction lecture only . . .
Microbial diseases, their pathogenesis and prophylaxis
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPH.pptx obstetrics and gynecology in nursing
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
master seminar digital applications in india
2.FourierTransform-ShortQuestionswithAnswers.pdf

Ground Gurus - Python Code Camp - Day 3 - Classes

  • 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.