SlideShare a Scribd company logo
1 of 17
Download to read offline
A Quick Python Tour


   Brought to you by
What is Python?
• Programming Language created by
  Guido van Rossum
• It has been around for over 20 years
• Dynamically typed, object-oriented
  language
• Runs on Win, Linux/Unix, Mac, OS/2 etc
• Versions: 2.x and 3.x
What can Python do?
•   Scripting
•   Rapid Prototyping
•   Text Processing
•   Web applications
•   GUI programs
•   Game Development
•   Database Applications
•   System Administrations
•   And many more.
A Sample Program
          function

def greetings(name=’’):
    ’’’Function that returns a message’’’
    if name==’’:                                       docstring
       msg = ”Hello Guest. Welcome!”
    else:
       msg = ”Hello %s. Welcome!” % name
    return msg
                           variable
indentation
>>> greetings(“John”)           #     name is ‘John’
‘Hello John. Welcome!’
                                        comment
>>> greetings()
‘Hello Guest. Welcome!’
Python Data Types
• Built-in types
   int, float, complex, long
• Sequences/iterables
      string
      dictionary
      list
     tuple
Built-in Types
• Integer
  >>> a = 5
• Floating-point number
  >>> b = 5.0
• Complex number
  >>> c = 1+2j
• Long integer
  >>> d = 12345678L
String
• Immutable sequence of characters enclosed in
  quotes
  >>> a = “Hello”
  >>> a.upper()    # change to uppercase
  ‘HELLO’
  >>> a[0:2]       # slicing
  ‘He’
List
• Container type that stores a sequence of items
• Data is enclosed within square brackets []
  >>> a = [“a”, “b”, “c”, “d”]
  >>> a.remove(“d”) # remove item “d”
  >>> a[0] = 1          # change 1st item to 1
  >>> a
  [ 1, “b”, “c” ]
Tuple
• Container type similar to list but is immutable
• More efficient in storage than list.
• Data is enclosed within braces ()
  >>> a = (‘a’, ‘b’, ‘c’)
  >>> a[1]
  ‘b’
  >>> a[0] = 1            # invalid
  >>> a += (1, 2, 3) # invalid
  >>> b = a+(1,2,3) # valid, create new tuple
Dictionary
• Container type to store data in key/value pairs
• Data is enclosed within curly braces {}
  >>> a = {“a”:1, “b”:2}
  >>> a.keys()
  [‘a’, ‘b’]
  >>> a.update({‘c’:3}) # add pair {‘c’:3}
  >>> a.items()
  [(‘a’, 1), (‘c’, 3), (‘b’, 2)]
Control Structures
• Conditional
   if, elif, else - branch into different paths
• Looping
   while        - iterate until condition is false
   for          - iterate over a defined range
• Additional control
   break       - terminate loop early
   continue    - skip current iteration
   pass        - empty statement that does nothing
if, else, elif
• Syntax:                    • Example:
  if condition1:               x=1
     statements                y=2
                               if x>y:
  [elif condition2:
                                  print “x is greater.”
     statements]               elif x<y:
  [else:                          print “y is greater.”
     statements]               else:
                                  print “x is equal to y.”
                             • Output:
                                y is greater.
while
• Syntax:               • Example:
  while condition:        x= 1
      statements          while x<4:
                             print x
                              x+=1
                        • Output:
                          1
                          2
                          3
for
• Syntax:                   • Example:
  for item in sequence:       for x in “abc”:
      statements                  print x
                            • Output:
                              a
                              b
                              c
Function
• A function or method is a group of statements
performing a specific task.
• Syntax:                     • Example:
   def fname(parameters):       def triangleArea(b, h):
       [‘’’ doc string ‘’’]       ‘’’Return triangle area‘’’
                                  area = 0.5 * b * h
        statements
                                  return area
       [return expression]
                              • Output:
                                  >>> triangleArea(5, 8)
                                  20.0
                                  >>> triangleArea.__doc__
                                  ‘Return triangle area’
class and object
• A class is a construct that represent a kind using
methods and variables. An object is an instance of a class.
 • Syntax:                   • Example:
  class ClassName:           class Person:
     [class documentation]      def __init__(self, name):
     class statements              self.name = name
                                def introduce(self):
                                   return “I am %s.” % self.name
                             • Output:
                             >>> a = Person(“John”). # object
                             >>> a.introduce()
                             ‘I am John.’
End of Tour

This is just a brief introduction.

What is next?
• Read PySchools Quick Reference
• Practice the online tutorial on PySchools


Have Fun!

More Related Content

What's hot

An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scalaXing
 
Object Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonObject Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonTendayi Mawushe
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scaladjspiewak
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Mohd Harris Ahmad Jaal
 
Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Bozhidar Boshnakov
 
Iniciando com jquery
Iniciando com jqueryIniciando com jquery
Iniciando com jqueryDanilo Sousa
 
Introduction to c
Introduction to cIntroduction to c
Introduction to cSayed Ahmed
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersGiovanni924
 
Scala for Java Developers - Intro
Scala for Java Developers - IntroScala for Java Developers - Intro
Scala for Java Developers - IntroDavid Copeland
 
Pharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntaxPharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntaxPharo
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Jorge Vásquez
 
ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021Jorge Vásquez
 
Exploring type level programming in Scala
Exploring type level programming in ScalaExploring type level programming in Scala
Exploring type level programming in ScalaJorge Vásquez
 

What's hot (18)

Python programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphismPython programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphism
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Object Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonObject Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in Python
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
 
Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)
 
Python : Dictionaries
Python : DictionariesPython : Dictionaries
Python : Dictionaries
 
Iniciando com jquery
Iniciando com jqueryIniciando com jquery
Iniciando com jquery
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
 
Scala: A brief tutorial
Scala: A brief tutorialScala: A brief tutorial
Scala: A brief tutorial
 
Scala for Java Developers - Intro
Scala for Java Developers - IntroScala for Java Developers - Intro
Scala for Java Developers - Intro
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
 
Pharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntaxPharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntax
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!
 
ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021
 
Exploring type level programming in Scala
Exploring type level programming in ScalaExploring type level programming in Scala
Exploring type level programming in Scala
 

Viewers also liked

Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Jacob Kaplan-Moss
 
Make It Cooler: Using Decentralized Version Control
Make It Cooler: Using Decentralized Version ControlMake It Cooler: Using Decentralized Version Control
Make It Cooler: Using Decentralized Version Controlindiver
 
Outside-In Development With Cucumber
Outside-In Development With CucumberOutside-In Development With Cucumber
Outside-In Development With CucumberBen Mabey
 
Prepare for JDK 9
Prepare for JDK 9Prepare for JDK 9
Prepare for JDK 9haochenglee
 
Introduction to Git for developers
Introduction to Git for developersIntroduction to Git for developers
Introduction to Git for developersDmitry Guyvoronsky
 
Two scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesTwo scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesSpin Lai
 
The WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecThe WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecBen Mabey
 

Viewers also liked (10)

Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
 
Make It Cooler: Using Decentralized Version Control
Make It Cooler: Using Decentralized Version ControlMake It Cooler: Using Decentralized Version Control
Make It Cooler: Using Decentralized Version Control
 
Capybara
CapybaraCapybara
Capybara
 
Outside-In Development With Cucumber
Outside-In Development With CucumberOutside-In Development With Cucumber
Outside-In Development With Cucumber
 
Prepare for JDK 9
Prepare for JDK 9Prepare for JDK 9
Prepare for JDK 9
 
Introduction to Git for developers
Introduction to Git for developersIntroduction to Git for developers
Introduction to Git for developers
 
Two scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesTwo scoops of Django - Security Best Practices
Two scoops of Django - Security Best Practices
 
The WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecThe WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpec
 
Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
 
Git Branching Model
Git Branching ModelGit Branching Model
Git Branching Model
 

Similar to A quick python_tour

Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developersJim Roepcke
 
python within 50 page .ppt
python within 50 page .pptpython within 50 page .ppt
python within 50 page .pptsushil155005
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : PythonRaghu Kumar
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless Jared Roesch
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a PythonistRaji Engg
 
Introduction to Python , Overview
Introduction to Python , OverviewIntroduction to Python , Overview
Introduction to Python , OverviewNB Veeresh
 
Getting started in Python presentation by Laban K
Getting started in Python presentation by Laban KGetting started in Python presentation by Laban K
Getting started in Python presentation by Laban KGDSCKYAMBOGO
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like PythonistaChiyoung Song
 
Lec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questionsLec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questionsYashJain47002
 
An Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in PythonAn Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in Pythonyashar Aliabasi
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, SwiftYandex
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Pythonkwatch
 
Pharo: Syntax in a Nutshell
Pharo: Syntax in a NutshellPharo: Syntax in a Nutshell
Pharo: Syntax in a NutshellMarcus Denker
 

Similar to A quick python_tour (20)

Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developers
 
python within 50 page .ppt
python within 50 page .pptpython within 50 page .ppt
python within 50 page .ppt
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
 
Python ppt
Python pptPython ppt
Python ppt
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
 
Introduction to Python , Overview
Introduction to Python , OverviewIntroduction to Python , Overview
Introduction to Python , Overview
 
Python assignment help
Python assignment helpPython assignment help
Python assignment help
 
Getting started in Python presentation by Laban K
Getting started in Python presentation by Laban KGetting started in Python presentation by Laban K
Getting started in Python presentation by Laban K
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like Pythonista
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Lec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questionsLec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questions
 
An Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in PythonAn Introduction to Tuple List Dictionary in Python
An Introduction to Tuple List Dictionary in Python
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Python
 
P3 2018 python_regexes
P3 2018 python_regexesP3 2018 python_regexes
P3 2018 python_regexes
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Pharo: Syntax in a Nutshell
Pharo: Syntax in a NutshellPharo: Syntax in a Nutshell
Pharo: Syntax in a Nutshell
 

Recently uploaded

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

A quick python_tour

  • 1. A Quick Python Tour Brought to you by
  • 2. What is Python? • Programming Language created by Guido van Rossum • It has been around for over 20 years • Dynamically typed, object-oriented language • Runs on Win, Linux/Unix, Mac, OS/2 etc • Versions: 2.x and 3.x
  • 3. What can Python do? • Scripting • Rapid Prototyping • Text Processing • Web applications • GUI programs • Game Development • Database Applications • System Administrations • And many more.
  • 4. A Sample Program function def greetings(name=’’): ’’’Function that returns a message’’’ if name==’’: docstring msg = ”Hello Guest. Welcome!” else: msg = ”Hello %s. Welcome!” % name return msg variable indentation >>> greetings(“John”) # name is ‘John’ ‘Hello John. Welcome!’ comment >>> greetings() ‘Hello Guest. Welcome!’
  • 5. Python Data Types • Built-in types  int, float, complex, long • Sequences/iterables  string  dictionary  list  tuple
  • 6. Built-in Types • Integer >>> a = 5 • Floating-point number >>> b = 5.0 • Complex number >>> c = 1+2j • Long integer >>> d = 12345678L
  • 7. String • Immutable sequence of characters enclosed in quotes >>> a = “Hello” >>> a.upper() # change to uppercase ‘HELLO’ >>> a[0:2] # slicing ‘He’
  • 8. List • Container type that stores a sequence of items • Data is enclosed within square brackets [] >>> a = [“a”, “b”, “c”, “d”] >>> a.remove(“d”) # remove item “d” >>> a[0] = 1 # change 1st item to 1 >>> a [ 1, “b”, “c” ]
  • 9. Tuple • Container type similar to list but is immutable • More efficient in storage than list. • Data is enclosed within braces () >>> a = (‘a’, ‘b’, ‘c’) >>> a[1] ‘b’ >>> a[0] = 1 # invalid >>> a += (1, 2, 3) # invalid >>> b = a+(1,2,3) # valid, create new tuple
  • 10. Dictionary • Container type to store data in key/value pairs • Data is enclosed within curly braces {} >>> a = {“a”:1, “b”:2} >>> a.keys() [‘a’, ‘b’] >>> a.update({‘c’:3}) # add pair {‘c’:3} >>> a.items() [(‘a’, 1), (‘c’, 3), (‘b’, 2)]
  • 11. Control Structures • Conditional  if, elif, else - branch into different paths • Looping  while - iterate until condition is false  for - iterate over a defined range • Additional control  break - terminate loop early  continue - skip current iteration  pass - empty statement that does nothing
  • 12. if, else, elif • Syntax: • Example: if condition1: x=1 statements y=2 if x>y: [elif condition2: print “x is greater.” statements] elif x<y: [else: print “y is greater.” statements] else: print “x is equal to y.” • Output: y is greater.
  • 13. while • Syntax: • Example: while condition: x= 1 statements while x<4: print x x+=1 • Output: 1 2 3
  • 14. for • Syntax: • Example: for item in sequence: for x in “abc”: statements print x • Output: a b c
  • 15. Function • A function or method is a group of statements performing a specific task. • Syntax: • Example: def fname(parameters): def triangleArea(b, h): [‘’’ doc string ‘’’] ‘’’Return triangle area‘’’ area = 0.5 * b * h statements return area [return expression] • Output: >>> triangleArea(5, 8) 20.0 >>> triangleArea.__doc__ ‘Return triangle area’
  • 16. class and object • A class is a construct that represent a kind using methods and variables. An object is an instance of a class. • Syntax: • Example: class ClassName: class Person: [class documentation] def __init__(self, name): class statements self.name = name def introduce(self): return “I am %s.” % self.name • Output: >>> a = Person(“John”). # object >>> a.introduce() ‘I am John.’
  • 17. End of Tour This is just a brief introduction. What is next? • Read PySchools Quick Reference • Practice the online tutorial on PySchools Have Fun!