Presented by: Prithwish Chakraborty
LET’S CODE!!!
Sponsored by: AKAMAI
Python : Object Oriented Programming
Reference: http://www.tutorialspoint.com/python/python_classes_objects.htm
2Let’s Code: Session 3
PythonVariables:Basic data structures :
ListsDictionariesTuples
Basic operators: Addition/subtractionDivision/Mutliplication
Functions??
3/28/2013
What have we learnt so far??
3Let’s Code: Session 3 3/28/2013
Recap of function syntax
4Let’s Code: Session 3
Problem: Build an employee database
3/28/2013
Let’s do something
5Let’s Code: Session 3
Problem: Build an employee database
What attributes do we want to keep? Employee Name: e.g. Sylvester StalloneEmployee Address: e.g. (Beverly Hills, California,
USA)Employee Id: e.g. 127001Employee Salary: e.g. $1000000
What operations do we want?What other things can we do?
3/28/2013
Let’s do something
6Let’s Code: Session 3
Problem: Build an employee database
What attributes do we want to keep?What operations do we want?
Get Employee NameGet Employee idChange Salary
Give 100$ bonus if address is in Beverly HillsAdd a new information about the employee
Add info about speciality e.g. “Mind Blowing Action Movies”What else can we do?
3/28/2013
Let’s do something
7Let’s Code: Session 3
Create an Employee:Which data structure to use ??
Lets use dict
Attributes:
3/28/2013
Let’s start off!!
Attribute Type Example
name string “Sylvester Stallone”
address tuple (“Beverly Hills”,”CA”,”USA”)
id int 127001
salary int 1000000
8Let’s Code: Session 3
Create an Employee:Functions:
Now let us extend this to a database >Non-object oriented wayObject Oriented way
3/28/2013
Let’s start off!!
Actions Example Logic
get_employee_name
“Sylvester Stallone”
get_employee_id 127001
change_salary if(address[0] == “Beverly Hills”): salary += 100
Add_new_info Add attribute: Speciality
9Let’s Code: Session 3
Basic philosophyA “container” to hold attributes and operations
realted to those attributes in one single place!!
Anybody having C background?? – lets start of by thinking of struct: container to hold data
How about if we have some funcitons?
What you ask about the syntax?? ok so be it
3/28/2013
OOPS – the world of infinite possibilites
10Let’s Code: Session 3 3/28/2013
OOPS – baby stepsExample of a class:
Special notes : self
11Let’s Code: Session 3 3/28/2013
OOPS – baby stepsExample of a class:
Special notes : self
Looking a bit deepr: where are these created
12Let’s Code: Session 3
Some other conceptsAdding attributes
Deleting instances
Control the delete operation
3/28/2013
OOPS –baby steps
13Let’s Code: Session 3
Problem: Build an employee database
What attributes do we want to keep?What operations do we want?What else can we do?
Extend definitons of EmployeeMultiple Inheritance
3/28/2013
Let’s do something
14Let’s Code: Session 3
Creating a “super Employee”
Use attributes the same as Employee but add a new attribute: position
Way out : Inheritance
3/28/2013
OOPS – ok time for some more steps
15Let’s Code: Session 3
Change the bonus function
Give 100$ more if CEOWay out function overloading
3/28/2013
OOPS – I wanna change the world
16Let’s Code: Session 3
Multiple InheritanceAnother “base class”
Creating the super Duper employee
3/28/2013
OOPS – wow every thing is so easy!!
17Let’s Code: Session 3
Operator overloading
Iterators
Generators
3/28/2013
Future Things
18Let’s Code: Session 3
A Big thanks to the sponsor for this session:
And best of all!! Akamai is currently recruiting for summer interns. All positions are listed at jobs.akamai.com or you can send resumes directly to [email protected]
3/28/2013
Acknowledgement
19Let’s Code: Session 3
Sample Codes: https://c9.io/pchakraborty/lets-code
Other refereces: http://docs.python.org/2/tutorial/classes.html
3/28/2013
References