SlideShare a Scribd company logo
1 of 24
Download to read offline
Shabda Raaj
   This is a workshop, not a talk.
   You are expected to code along.
   So pull out your laptops.
   Install python, ipython and komodo edit. (Or
    editor of your choice.)
   Assume that you know programming in any
    language.
   So we don’t spend a lot of time explaining
    basics.
   BUT, stop and ask if something doesn't make
    sense.
   AND Definitely Stop me if I am going too
    slow, too fast, or making no sense.
   Dynamically but strongly typed.
   Very object oriented - everything is an object.
   But pragmatic - Objects aren't everthing.
   Allows various paradigms of programming -
    OO, procedural, functional.
   Shallow learning curve, but powerful powerful
    capabilities available, when you need them.
   import this
   We will come back to this slide.
   Hello world
   >>> print "Hello World"
   for, while, if, else, break, continue
       -Yeah they are available, surprised?
   We will use them in a moment, but after we
    see the data structures available.
   List - Like ArrayList in Java
   Tuple - Like List, but immutable
   Dict - Like Hashmaps in Java
   For Loop
           for el in iterable:
              [block statement]
       the classic for loop
           for (int i; i < n; i++){}
           for i in range(n):
              #Work with I
           While condition:
              [block]
   break, continue. Normal operation - break out of
    current loop.
   If: elif: else:

    if condition:
        [block]
     else:
        [block]
   You have enough information now to write a
    solution
   Problem statement:
   Write a program that prints the numbers from
    1 to 100. But for multiples of three print "Fizz"
    instead of the number and for the multiples of
    five print "Buzz". For numbers which are
    multiples of both three and five print
    "FizzBuzz".
   def function_name(argument_list):
            [block]
   Functions can have default value.
          def fizzbuzz(till=100, fizz='fizz', buzz='buzz'):
            #fi zzbuzz code
   Functions can have variable length values.
          ex multiply all values passed to a function.
   Functions are first class - They are objects too.
    They can be passed to other
   functions, assigned to variables etc.
   class ClassName(base_classes):
          [block]
   Classes are first class too
   They can be passed to function, and assigned
    to variables.
   If we list all the natural numbers below 10 that
    are multiples of 3 or 5, we get 3, 5, 6 and 9.
    The sum of these multiples is 23.
   Find the sum of all the multiples of 3 or 5
    below 1000
   The last solution was needlessly verbose
   List comprehension: Take a list and transform it.
   Standard list comprehension syntax - [expr(i) for i
    in iterable if condition]
   List of all squares: [i*i for i in range(1,11)]
   List of all squares of even numbers: [i*i for i in
    range(1,11) if i%2 == 0]
   So solution to last problem is just
   sum([i*i for i in range(1,1001) if i%3 == 0 or
    i%5==0])
   List comprehensions are python way to do
    functional programming constructs
   [function(i) for i in iterable if condition] is
    filter(func2, map(func1, iter))
   Lets see how this list comprehension maps to
    functional concepts
   Get the list of squares of even numbers
   Open a file with - open('location') or
    file('location')
   or give a mode - open('location', 'rw')
   iterate as
          for line in open_file.readlines():
                   print line #Or whatever
   or
   string = open_file.read()
   Find the most commonly used word in the
    Alice in wonderland text.
   Batteries included
       math
       datetime
       string
       re
       random
       os
       pickle
   Do a dir() and see for yourself.
   And a lot, lot more: http://docs.python.org/library/
   Dynamically but strongly typed.
   Very object oriented - everything is an object.
   But pragmatic - Objects aren't everything.
   Allows various paradigms of programming -
    OO, procedural, functional.
   Shallow learning curve, but powerful powerful
    capabilities available, when you need them.
   import this
   Syntacting sugar for
       foo_func =docorator_func(foo_func)
   Many useful frameworks
       Tornado,
       Pylons,
       Turbogears
       Django
       GAE
   Django: Most actively developed and largest
    community participation
   PIL
   Mechanize
   Beautiful Soup
   Element Tree
   python.org
   diveintopython.org
   uswaretech.com/blog
   Thank You.
   You can give feedback, ask questions at
    shabda@uswaretech.com

More Related Content

What's hot

A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp languageDavid Gu
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Threeamiable_indian
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAMaulik Borsaniya
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 
Tackling repetitive tasks with serial or parallel programming in R
Tackling repetitive tasks with serial or parallel programming in RTackling repetitive tasks with serial or parallel programming in R
Tackling repetitive tasks with serial or parallel programming in RLun-Hsien Chang
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISPDevnology
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Bryan O'Sullivan
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Twoamiable_indian
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talkJohn Stevenson
 

What's hot (20)

A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Python basic
Python basicPython basic
Python basic
 
Advance python
Advance pythonAdvance python
Advance python
 
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
 
Os Goodger
Os GoodgerOs Goodger
Os Goodger
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Python Basics
Python Basics Python Basics
Python Basics
 
Tackling repetitive tasks with serial or parallel programming in R
Tackling repetitive tasks with serial or parallel programming in RTackling repetitive tasks with serial or parallel programming in R
Tackling repetitive tasks with serial or parallel programming in R
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
 
Python
PythonPython
Python
 
Chapter 7 String
Chapter 7 StringChapter 7 String
Chapter 7 String
 
Python tuple
Python   tuplePython   tuple
Python tuple
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
Lisp
LispLisp
Lisp
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talk
 
python codes
python codespython codes
python codes
 

Similar to Beginning Python

Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)Ralf Laemmel
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxCatherineVania1
 
Brogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and GitBrogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and GitRon Reiter
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answerskavinilavuG
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingRichardWarburton
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answersRojaPriya
 
How to use tensorflow
How to use tensorflowHow to use tensorflow
How to use tensorflowhyunyoung Lee
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospectivechenge2k
 
Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like PythonistaChiyoung Song
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxpriestmanmable
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2sadhana312471
 
Natural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usageNatural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usagehyunyoung Lee
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyTypesafe
 

Similar to Beginning Python (20)

Beginning Python
Beginning PythonBeginning Python
Beginning Python
 
Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)
 
Python Session - 4
Python Session - 4Python Session - 4
Python Session - 4
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
Brogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and GitBrogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and Git
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Erlang session1
Erlang session1Erlang session1
Erlang session1
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
How to use tensorflow
How to use tensorflowHow to use tensorflow
How to use tensorflow
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like Pythonista
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2
 
Natural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usageNatural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usage
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 

More from Agiliq Info Solutions India Pvt Ltd (6)

Rails for Django developers
Rails for Django developersRails for Django developers
Rails for Django developers
 
Lbs apps-monetization
Lbs apps-monetizationLbs apps-monetization
Lbs apps-monetization
 
Python Metaclass and How Django uses them: Foss 2010
Python Metaclass and How Django uses them: Foss 2010Python Metaclass and How Django uses them: Foss 2010
Python Metaclass and How Django uses them: Foss 2010
 
Django design-patterns
Django design-patternsDjango design-patterns
Django design-patterns
 
The django quiz
The django quizThe django quiz
The django quiz
 
How to launch a startup
How to launch a startupHow to launch a startup
How to launch a startup
 

Recently uploaded

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
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
 
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
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
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
 
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
 
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 Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Beginning Python

  • 2. This is a workshop, not a talk.  You are expected to code along.  So pull out your laptops.  Install python, ipython and komodo edit. (Or editor of your choice.)
  • 3. Assume that you know programming in any language.  So we don’t spend a lot of time explaining basics.  BUT, stop and ask if something doesn't make sense.  AND Definitely Stop me if I am going too slow, too fast, or making no sense.
  • 4. Dynamically but strongly typed.  Very object oriented - everything is an object.  But pragmatic - Objects aren't everthing.  Allows various paradigms of programming - OO, procedural, functional.  Shallow learning curve, but powerful powerful capabilities available, when you need them.  import this  We will come back to this slide.
  • 5. Hello world  >>> print "Hello World"
  • 6. for, while, if, else, break, continue  -Yeah they are available, surprised?  We will use them in a moment, but after we see the data structures available.
  • 7. List - Like ArrayList in Java  Tuple - Like List, but immutable  Dict - Like Hashmaps in Java
  • 8. For Loop  for el in iterable:  [block statement]  the classic for loop  for (int i; i < n; i++){}  for i in range(n):  #Work with I  While condition:  [block]  break, continue. Normal operation - break out of current loop.
  • 9. If: elif: else:  if condition:  [block]  else:  [block]
  • 10. You have enough information now to write a solution  Problem statement:  Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
  • 11. def function_name(argument_list):  [block]  Functions can have default value.  def fizzbuzz(till=100, fizz='fizz', buzz='buzz'):  #fi zzbuzz code  Functions can have variable length values.  ex multiply all values passed to a function.  Functions are first class - They are objects too. They can be passed to other  functions, assigned to variables etc.
  • 12. class ClassName(base_classes):  [block]  Classes are first class too  They can be passed to function, and assigned to variables.
  • 13. If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.  Find the sum of all the multiples of 3 or 5 below 1000
  • 14. The last solution was needlessly verbose  List comprehension: Take a list and transform it.  Standard list comprehension syntax - [expr(i) for i in iterable if condition]  List of all squares: [i*i for i in range(1,11)]  List of all squares of even numbers: [i*i for i in range(1,11) if i%2 == 0]  So solution to last problem is just  sum([i*i for i in range(1,1001) if i%3 == 0 or i%5==0])
  • 15. List comprehensions are python way to do functional programming constructs  [function(i) for i in iterable if condition] is filter(func2, map(func1, iter))  Lets see how this list comprehension maps to functional concepts  Get the list of squares of even numbers
  • 16. Open a file with - open('location') or file('location')  or give a mode - open('location', 'rw')  iterate as  for line in open_file.readlines():  print line #Or whatever  or  string = open_file.read()
  • 17. Find the most commonly used word in the Alice in wonderland text.
  • 18. Batteries included  math  datetime  string  re  random  os  pickle  Do a dir() and see for yourself.  And a lot, lot more: http://docs.python.org/library/
  • 19. Dynamically but strongly typed.  Very object oriented - everything is an object.  But pragmatic - Objects aren't everything.  Allows various paradigms of programming - OO, procedural, functional.  Shallow learning curve, but powerful powerful capabilities available, when you need them.  import this
  • 20. Syntacting sugar for  foo_func =docorator_func(foo_func)
  • 21. Many useful frameworks  Tornado,  Pylons,  Turbogears  Django  GAE  Django: Most actively developed and largest community participation
  • 22. PIL  Mechanize  Beautiful Soup  Element Tree
  • 23. python.org  diveintopython.org  uswaretech.com/blog
  • 24. Thank You.  You can give feedback, ask questions at shabda@uswaretech.com