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

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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!