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

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

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!