SlideShare a Scribd company logo
Object Oriented
                            Python



Tuesday, April 24, 12
Object Oriented
                            Python
                        The way programming was meant to be




Tuesday, April 24, 12
Who we are




Tuesday, April 24, 12
Who we are


                              Anna




Tuesday, April 24, 12
Who we are


                         David   Anna




Tuesday, April 24, 12
Why do I care about
                              classes?
                        • Code organization
                        • Readability
                        • Making large-scale changes easier
                        • What everybody does these days
                        • Encapsulation (SAT word!)

Tuesday, April 24, 12
What is a class?
                         Factory for creating nouns
                         based on your description




Tuesday, April 24, 12
What is a class?
                         Factory for creating nouns
                         based on your description




Tuesday, April 24, 12
What does an object
                             contain?




Tuesday, April 24, 12
What does an object
                               contain?
                        Local Data




Tuesday, April 24, 12
What does an object
                               contain?
                        Local Data

                            Name: David
                            Birthday: Dec 18
                            Job: Software Engineer




Tuesday, April 24, 12
What does an object
                               contain?
                        Local Data

                            Name: David
                            Birthday: Dec 18
                            Job: Software Engineer


                                        Actions
                                         say_hello()
                                         eat_spaghetti()
                                         teach_a_class()

Tuesday, April 24, 12
What does an object
                               contain?
                        Local Data                         Local Data

                            Name: David              Name: Anna
                            Birthday: Dec 18         Birthday: Sep 6
                            Job: Software Engineer   Job: Entrepreneur


                                        Actions
                                         say_hello()
                                         eat_spaghetti()
                                         teach_a_class()

Tuesday, April 24, 12
What does an object
                               contain?
                        Local Data                         Local Data

                            Name: David              Name: Anna
                            Birthday: Dec 18         Birthday: Sep 6
                            Job: Software Engineer   Job: Entrepreneur


                                        Actions
                                         say_hello()
                                         eat_spaghetti()
                                         teach_a_class()

Tuesday, April 24, 12
Syntax
                        Definition
        class User(object):
          name = "Jack"
          birthday = "Jan 2"
          job = "student"

             def say_hello(self):
               print "Hello, I'm " + self.name

             def eat_spaghetti(self):
               print "Yum!"




Tuesday, April 24, 12
Syntax
                        Definition                       Usage
                                                 >>> jack1 = User()
        class User(object):
                                                 >>> print jack1.name
          name = "Jack"
                                                 "Jack"
          birthday = "Jan 2"
          job = "student"
                                                 >>> jack2 = User()
                                                 >>> print jack2.name
             def say_hello(self):
                                                 "Jack"
               print "Hello, I'm " + self.name
                                                 >>> jack1.say_hello()
             def eat_spaghetti(self):
                                                 "Hello, I'm Jack"
               print "Yum!"
                                                 >>> jack2.eat_spaghetti()
                                                 "Yum!"



Tuesday, April 24, 12
Syntax
                         Definition                      Usage
                                                 >>> jack1 = User()
        class User(object):
                                                 >>> print jack1.name
          name = "Jack"
                                                 "Jack"
          birthday = "Jan 2"
          job = "student"
                                                 >>> jack2 = User()
                                                 >>> print jack2.name
             def say_hello(self):
                                                 "Jack"
               print "Hello, I'm " + self.name
                                                 >>> jack1.say_hello()
             def eat_spaghetti(self):
                                                 "Hello, I'm Jack"
               print "Yum!"
                                                 >>> jack2.eat_spaghetti()
                                                 "Yum!"


                        One class, multiple objects
Tuesday, April 24, 12
Local Data
      class User(object):                        >>> harry = User("Harry")
        def __init__(self, name):                >>> sally = User("Sally")
          self.name = name                       >>> harry.say_hello()
                                                 "Hello, I'm Harry"
           def say_hello(self):                  >>> sally.say_hello()
             print "Hello, I'm " + self.name     "Hello, I'm Sally"
                                                 >>> harry.greet(sally)
           def greet(self, other):               "Hi Sally, I'm Harry!"
             print "Hi " + other.name + ", " +   >>> sally.greet(harry)
                    "I'm " + self.name + "!"     "Hi Harry, I'm Sally!"




Tuesday, April 24, 12
Local Data
      class User(object):                        >>> harry = User("Harry")
        def __init__(self, name):                >>> sally = User("Sally")
          self.name = name                       >>> harry.say_hello()
                                                 "Hello, I'm Harry"
           def say_hello(self):                  >>> sally.say_hello()
             print "Hello, I'm " + self.name     "Hello, I'm Sally"
                                                 >>> harry.greet(sally)
           def greet(self, other):               "Hi Sally, I'm Harry!"
             print "Hi " + other.name + ", " +   >>> sally.greet(harry)
                    "I'm " + self.name + "!"     "Hi Harry, I'm Sally!"
                                                 >>> harry.name = "Frank"
                                                 >>> harry.say_hello()
                                                 "Hello, I'm Frank!"



Tuesday, April 24, 12
Banking Program
                           Objects we’ll need:

                               • Banks
                               • Users
                               • Accounts


Tuesday, April 24, 12
Main Program
                            •   program:

                                •bank classbank object.method.
                                   create
                        • create create user object.
                                            with log in
                                •user class with name & password
                        • create log in.
                                •account class with amount
                        • create create account object.
                                •
                                • add money.

Tuesday, April 24, 12
Main Program
                            •   program:

                                •bank classbank object.method.
                                   create
                        • create create user object.
                                            with log in
                                •user class with name & password
                        • create log in.
                                •account class with amount
                        • create create account object.
                                •
                                • add money.

Tuesday, April 24, 12
Classes & Objects




Tuesday, April 24, 12
Bank Class




Tuesday, April 24, 12
User Class




Tuesday, April 24, 12
Account Class




Tuesday, April 24, 12
Tuesday, April 24, 12
Main Program
                        •   program:

                            •   create bank object.

                            •   create user object.

                            •   log in.

                            •   create account object.

                            •   add money.



Tuesday, April 24, 12
Main Program




Tuesday, April 24, 12
Main Program
                            •   program:

                                •bank classbank object.method.
                                   create
                        • create create user object.
                                            with log in
                                •user class with name & password
                        • create log in.
                                •account class with amount
                        • create create account object.
                                •
                                • add money.

Tuesday, April 24, 12
Main Program
                            •   program:

                                •bank classbank object.method.
                                   create
                        • create create user object.
                                            with log in
                                •user class with name & password
                        • create log in.
                                •account class with amount
                        • create create account object.
                                •
                                • add money.

Tuesday, April 24, 12
Bank Class




Tuesday, April 24, 12
Tuesday, April 24, 12
Main Program




Tuesday, April 24, 12
What if changes
                        need to be made?


Tuesday, April 24, 12
Banking Example
        >>>         bank = Bank()
        >>>         account_alice = Account(bank)
        >>>         account_alice.deposit(200)
        >>>         account_bob = Account(bank)
        >>>         account_bob.deposit(250)
        >>>         account_carol = Account(bank)
        >>>         account_carol.deposit(100)




         account_alice.balance: 200
                                         account_bob.balance: 250

                                                             account_carol.balance: 100


Tuesday, April 24, 12
Banking Example
        >>>         bank = Bank()
                                                        >>>     account_alice.deposit(100)
        >>>         account_alice = Account(bank)
                                                        >>>     account_bob.deposit(50)
        >>>         account_alice.deposit(200)
                                                        >>>     account_carol.withdraw(60)
        >>>         account_bob = Account(bank)
                                                        >>>     account_alice.withdraw(200)
        >>>         account_bob.deposit(250)
                                                        >>>     account_carol.deposit(200)
        >>>         account_carol = Account(bank)
                                                        >>>     account_bob.withdraw(80)
        >>>         account_carol.deposit(100)




        account_alice.balance: 100

                                     account_bob.balance: 220

                                                           account_carol.balance: 240


Tuesday, April 24, 12
Changes!
                        The government has just declared that
                          all bank deposits will be taxed %5.




Tuesday, April 24, 12
Changes!
                        The government has just declared that
                          all bank deposits will be taxed %5.

                                   Oh no!


Tuesday, April 24, 12
Changes!
                          The government has just declared that
                            all bank deposits will be taxed %5.

                                     Oh no!
                        Do we have to rewrite our entire program?




Tuesday, April 24, 12
Changes!
                          The government has just declared that
                            all bank deposits will be taxed %5.

                                     Oh no!
                        Do we have to rewrite our entire program?


                                      Nope!
Tuesday, April 24, 12
Original Version
                        class Account(object):
                           balance = 0

                          def deposit(self, amount):
                            self.balance = self.balance + amount

                          def withdraw(self, amount):
                            self.balance = self.balance - amount




Tuesday, April 24, 12
New Version
                        class Account(object):
                           balance = 0

                          def deposit(self, amount):
                            tax = amount * 5/100
                            remaining = amount - tax
                            self.balance = self.balance + remaining

                          def withdraw(self, amount):
                            self.balance = self.balance - amount




Tuesday, April 24, 12
Still Works
        >>>         bank = Bank()
                                                        >>>   account_alice.deposit(100)
        >>>         account_alice = Account(bank)
                                                        >>>   account_bob.deposit(50)
        >>>         account_alice.deposit(200)
                                                        >>>   account_carol.withdraw(60)
        >>>         account_bob = Account(bank)
                                                        >>>   account_alice.withdraw(200)
        >>>         account_bob.deposit(250)
                                                        >>>   account_carol.deposit(200)
        >>>         account_carol = Account(bank)
                                                        >>>   account_bob.withdraw(80)
        >>>         account_carol.deposit(100)




         account_alice.balance: 95

                                    account_bob.balance: 218.50

                                                            account_carol.balance: 230


Tuesday, April 24, 12
Any questions?

                        Classes?        Methods?

                             Objects?
                                        Syntax?
                        Local data?
Tuesday, April 24, 12

More Related Content

Recently uploaded

Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 

Recently uploaded (20)

Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Oo python

  • 1. Object Oriented Python Tuesday, April 24, 12
  • 2. Object Oriented Python The way programming was meant to be Tuesday, April 24, 12
  • 3. Who we are Tuesday, April 24, 12
  • 4. Who we are Anna Tuesday, April 24, 12
  • 5. Who we are David Anna Tuesday, April 24, 12
  • 6. Why do I care about classes? • Code organization • Readability • Making large-scale changes easier • What everybody does these days • Encapsulation (SAT word!) Tuesday, April 24, 12
  • 7. What is a class? Factory for creating nouns based on your description Tuesday, April 24, 12
  • 8. What is a class? Factory for creating nouns based on your description Tuesday, April 24, 12
  • 9. What does an object contain? Tuesday, April 24, 12
  • 10. What does an object contain? Local Data Tuesday, April 24, 12
  • 11. What does an object contain? Local Data Name: David Birthday: Dec 18 Job: Software Engineer Tuesday, April 24, 12
  • 12. What does an object contain? Local Data Name: David Birthday: Dec 18 Job: Software Engineer Actions say_hello() eat_spaghetti() teach_a_class() Tuesday, April 24, 12
  • 13. What does an object contain? Local Data Local Data Name: David Name: Anna Birthday: Dec 18 Birthday: Sep 6 Job: Software Engineer Job: Entrepreneur Actions say_hello() eat_spaghetti() teach_a_class() Tuesday, April 24, 12
  • 14. What does an object contain? Local Data Local Data Name: David Name: Anna Birthday: Dec 18 Birthday: Sep 6 Job: Software Engineer Job: Entrepreneur Actions say_hello() eat_spaghetti() teach_a_class() Tuesday, April 24, 12
  • 15. Syntax Definition class User(object): name = "Jack" birthday = "Jan 2" job = "student" def say_hello(self): print "Hello, I'm " + self.name def eat_spaghetti(self): print "Yum!" Tuesday, April 24, 12
  • 16. Syntax Definition Usage >>> jack1 = User() class User(object): >>> print jack1.name name = "Jack" "Jack" birthday = "Jan 2" job = "student" >>> jack2 = User() >>> print jack2.name def say_hello(self): "Jack" print "Hello, I'm " + self.name >>> jack1.say_hello() def eat_spaghetti(self): "Hello, I'm Jack" print "Yum!" >>> jack2.eat_spaghetti() "Yum!" Tuesday, April 24, 12
  • 17. Syntax Definition Usage >>> jack1 = User() class User(object): >>> print jack1.name name = "Jack" "Jack" birthday = "Jan 2" job = "student" >>> jack2 = User() >>> print jack2.name def say_hello(self): "Jack" print "Hello, I'm " + self.name >>> jack1.say_hello() def eat_spaghetti(self): "Hello, I'm Jack" print "Yum!" >>> jack2.eat_spaghetti() "Yum!" One class, multiple objects Tuesday, April 24, 12
  • 18. Local Data class User(object): >>> harry = User("Harry") def __init__(self, name): >>> sally = User("Sally") self.name = name >>> harry.say_hello() "Hello, I'm Harry" def say_hello(self): >>> sally.say_hello() print "Hello, I'm " + self.name "Hello, I'm Sally" >>> harry.greet(sally) def greet(self, other): "Hi Sally, I'm Harry!" print "Hi " + other.name + ", " + >>> sally.greet(harry) "I'm " + self.name + "!" "Hi Harry, I'm Sally!" Tuesday, April 24, 12
  • 19. Local Data class User(object): >>> harry = User("Harry") def __init__(self, name): >>> sally = User("Sally") self.name = name >>> harry.say_hello() "Hello, I'm Harry" def say_hello(self): >>> sally.say_hello() print "Hello, I'm " + self.name "Hello, I'm Sally" >>> harry.greet(sally) def greet(self, other): "Hi Sally, I'm Harry!" print "Hi " + other.name + ", " + >>> sally.greet(harry) "I'm " + self.name + "!" "Hi Harry, I'm Sally!" >>> harry.name = "Frank" >>> harry.say_hello() "Hello, I'm Frank!" Tuesday, April 24, 12
  • 20. Banking Program Objects we’ll need: • Banks • Users • Accounts Tuesday, April 24, 12
  • 21. Main Program • program: •bank classbank object.method. create • create create user object. with log in •user class with name & password • create log in. •account class with amount • create create account object. • • add money. Tuesday, April 24, 12
  • 22. Main Program • program: •bank classbank object.method. create • create create user object. with log in •user class with name & password • create log in. •account class with amount • create create account object. • • add money. Tuesday, April 24, 12
  • 28. Main Program • program: • create bank object. • create user object. • log in. • create account object. • add money. Tuesday, April 24, 12
  • 30. Main Program • program: •bank classbank object.method. create • create create user object. with log in •user class with name & password • create log in. •account class with amount • create create account object. • • add money. Tuesday, April 24, 12
  • 31. Main Program • program: •bank classbank object.method. create • create create user object. with log in •user class with name & password • create log in. •account class with amount • create create account object. • • add money. Tuesday, April 24, 12
  • 35. What if changes need to be made? Tuesday, April 24, 12
  • 36. Banking Example >>> bank = Bank() >>> account_alice = Account(bank) >>> account_alice.deposit(200) >>> account_bob = Account(bank) >>> account_bob.deposit(250) >>> account_carol = Account(bank) >>> account_carol.deposit(100) account_alice.balance: 200 account_bob.balance: 250 account_carol.balance: 100 Tuesday, April 24, 12
  • 37. Banking Example >>> bank = Bank() >>> account_alice.deposit(100) >>> account_alice = Account(bank) >>> account_bob.deposit(50) >>> account_alice.deposit(200) >>> account_carol.withdraw(60) >>> account_bob = Account(bank) >>> account_alice.withdraw(200) >>> account_bob.deposit(250) >>> account_carol.deposit(200) >>> account_carol = Account(bank) >>> account_bob.withdraw(80) >>> account_carol.deposit(100) account_alice.balance: 100 account_bob.balance: 220 account_carol.balance: 240 Tuesday, April 24, 12
  • 38. Changes! The government has just declared that all bank deposits will be taxed %5. Tuesday, April 24, 12
  • 39. Changes! The government has just declared that all bank deposits will be taxed %5. Oh no! Tuesday, April 24, 12
  • 40. Changes! The government has just declared that all bank deposits will be taxed %5. Oh no! Do we have to rewrite our entire program? Tuesday, April 24, 12
  • 41. Changes! The government has just declared that all bank deposits will be taxed %5. Oh no! Do we have to rewrite our entire program? Nope! Tuesday, April 24, 12
  • 42. Original Version class Account(object): balance = 0 def deposit(self, amount): self.balance = self.balance + amount def withdraw(self, amount): self.balance = self.balance - amount Tuesday, April 24, 12
  • 43. New Version class Account(object): balance = 0 def deposit(self, amount): tax = amount * 5/100 remaining = amount - tax self.balance = self.balance + remaining def withdraw(self, amount): self.balance = self.balance - amount Tuesday, April 24, 12
  • 44. Still Works >>> bank = Bank() >>> account_alice.deposit(100) >>> account_alice = Account(bank) >>> account_bob.deposit(50) >>> account_alice.deposit(200) >>> account_carol.withdraw(60) >>> account_bob = Account(bank) >>> account_alice.withdraw(200) >>> account_bob.deposit(250) >>> account_carol.deposit(200) >>> account_carol = Account(bank) >>> account_bob.withdraw(80) >>> account_carol.deposit(100) account_alice.balance: 95 account_bob.balance: 218.50 account_carol.balance: 230 Tuesday, April 24, 12
  • 45. Any questions? Classes? Methods? Objects? Syntax? Local data? Tuesday, April 24, 12