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

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 

Recently uploaded (20)

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 

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