lets code classes_python

Download Lets code classes_python

Post on 19-May-2015

253 views

Category:

Technology

0 download

Embed Size (px)

DESCRIPTION

Classes in python

TRANSCRIPT

  • 1. Presented by: Prithwish ChakrabortyLETS CODE!!!Sponsored by: AKAMAIReference: http://www.tutorialspoint.com/python/python_classes_objects.htm

2. Python Variables: Basic data structures : Lists Dictionaries Tuples Basic operators: Addition/subtraction Division/Mutliplication Functions??3/28/2013 1Lets Code: Session 3 3. 3/28/2013 2Lets Code: Session 3 4. Problem: Build an employee database3/28/2013 3Lets Code: Session 3 5. Problem: Build an employee database What attributes do we want to keep? Employee Name: e.g. Sylvester Stallone Employee Address: e.g. (Beverly Hills, California, USA) Employee Id: e.g. 127001 Employee Salary: e.g. $1000000 What operations do we want? What other things can we do?3/28/2013 4Lets Code: Session 3 6. Problem: Build an employee database What attributes do we want to keep? What operations do we want? Get Employee Name Get Employee id Change Salary Give 100$ bonus if address is in Beverly Hills Add a new information about the employee Add info about speciality e.g. Mind Blowing Action Movies What else can we do?3/28/2013 5Lets Code: Session 3 7. Create an Employee: Which data structure to use ?? Lets use dict Attributes:3/28/2013 6Lets Code: Session 3Attribute Type Examplename string Sylvester Stalloneaddress tuple (Beverly Hills,CA,USA)id int 127001salary int 1000000 8. Create an Employee: Functions: Now let us extend this to a database > Non-object oriented way Object Oriented way3/28/2013 7Lets Code: Session 3Actions Example Logicget_employee_name Sylvester Stalloneget_employee_id 127001change_salary if(address[0] == Beverly Hills): salary += 100Add_new_info Add attribute: Speciality 9. Basic philosophy A container to hold attributes and operations realtedto those attributes in one single place!! Anybody having C background?? lets start of bythinking of struct: container to hold data How about if we have some funcitons? What you ask about the syntax?? ok so be it3/28/2013 8Lets Code: Session 3 10. 3/28/2013 9Lets Code: Session 3 Example of a class: Special notes : self 11. 3/28/2013 10Lets Code: Session 3 Example of a class: Special notes : self Looking a bit deepr: where are these created 12. Some other concepts Adding attributes Deleting instances Control the delete operation3/28/2013 11Lets Code: Session 3 13. 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 Employee Multiple Inheritance3/28/2013 12Lets Code: Session 3 14. Creating a super Employee Use attributes the same as Employee but add a newattribute: position Way out : Inheritance3/28/2013 13Lets Code: Session 3 15. Change the bonus function Give 100$ more if CEO Way out function overloading3/28/2013 14Lets Code: Session 3 16. Multiple Inheritance Another base class Creating the super Duper employee3/28/2013 15Lets Code: Session 3 17. Operator overloading Iterators Generators3/28/2013 16Lets Code: Session 3 18. A Big thanks to the sponsor for this session: And best of all!! Akamai is currently recruiting forsummer interns. All positions are listed atjobs.akamai.com or you can send resumes directly togkoenig@akamai.com3/28/2013 17Lets Code: Session 3 19. Sample Codes:https://c9.io/pchakraborty/lets-code Other refereces:http://docs.python.org/2/tutorial/classes.html3/28/2013 18Lets Code: Session 3