Lets code classes_python

368 views
315 views

Published on

Classes in python

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
368
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Jump to code: Work through it.
  • Jump to code: Create Standalone functions
  • Second bullet: cue – type in a few attribute namesThird bullet: cue – type in a few function names
  • Cue: go through the concepts:start with class variablefunctionexample of an initializationnotes about init
  • Cue: go through the concepts:start with class variablefunctionexample of an initializationnotes about init
  • Cue: go to the demo
  • Lets code classes_python

    1. 1. Presented by: Prithwish ChakrabortyLET’S CODE!!!Sponsored by: AKAMAIReference: http://www.tutorialspoint.com/python/python_classes_objects.htm
    2. 2.  Python Variables: Basic data structures : Lists Dictionaries Tuples Basic operators: Addition/subtraction Division/Mutliplication Functions??3/28/2013 1Let’s Code: Session 3
    3. 3. 3/28/2013 2Let’s Code: Session 3
    4. 4.  Problem: Build an employee database3/28/2013 3Let’s Code: Session 3
    5. 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 4Let’s Code: Session 3
    6. 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 5Let’s Code: Session 3
    7. 7.  Create an Employee: Which data structure to use ?? Lets use dict Attributes:3/28/2013 6Let’s Code: Session 3Attribute Type Examplename string “Sylvester Stallone”address tuple (“Beverly Hills”,”CA”,”USA”)id int 127001salary int 1000000
    8. 8.  Create an Employee: Functions: Now let us extend this to a database > Non-object oriented way Object Oriented way3/28/2013 7Let’s Code: Session 3Actions Example Logicget_employee_name “Sylvester Stallone”get_employee_id 127001change_salary if(address[0] == “Beverly Hills”): salary += 100Add_new_info Add attribute: Speciality
    9. 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 8Let’s Code: Session 3
    10. 10. 3/28/2013 9Let’s Code: Session 3 Example of a class: Special notes : self
    11. 11. 3/28/2013 10Let’s Code: Session 3 Example of a class: Special notes : self Looking a bit deepr: where are these created
    12. 12.  Some other concepts Adding attributes Deleting instances Control the delete operation3/28/2013 11Let’s Code: Session 3
    13. 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 12Let’s Code: Session 3
    14. 14.  Creating a “super Employee” Use attributes the same as Employee but add a newattribute: position Way out : Inheritance3/28/2013 13Let’s Code: Session 3
    15. 15.  Change the bonus function Give 100$ more if CEO Way out function overloading3/28/2013 14Let’s Code: Session 3
    16. 16.  Multiple Inheritance Another “base class” Creating the super Duper employee3/28/2013 15Let’s Code: Session 3
    17. 17.  Operator overloading Iterators Generators3/28/2013 16Let’s Code: Session 3
    18. 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 17Let’s Code: Session 3
    19. 19.  Sample Codes:https://c9.io/pchakraborty/lets-code Other refereces:http://docs.python.org/2/tutorial/classes.html3/28/2013 18Let’s Code: Session 3

    ×