SlideShare a Scribd company logo
Python Bootcamp - C4Dlab




             SCI labs, University of Nairobi
             Nov 24th 2013

             Kenny Rachuonyo
Introduction to Python
    Features of Python
●   Simplicity - pseudocode
●   Free and Open Source - community
●   High-level – no low-level mngt
●   Interpreted – run from source
●   Object-Oriented – simple to use
●   Extensible – C/C++
Features (cont.)
●   Embeddable – games, graphics,
●   Extensive Libraries (batteries included) – data
    compression, OS, Networking, Internet,
    Multimedia, Graphics
Python in the Industry
    Web
●   Google – Youtube, backend tasks..
●   Reddit – news aggregation site
●   Disqus – commenting service
●   Numerous web frameworks – django, Zope,
    webapp2, web.py, pyramid, flask
Python in the Industry
    Desktop
●   Games – Counterstrike, Civilization IV
●   Cinema 4D – Graphics
●   Dropbox
●   GUI frameworks – PyGTK, PyQT,
Python in the Industry
    Scientific Computing
●   NASA
●   Packages: Scipy, Numpy, Matplotlib,
Python in the Industry
    Mobile
●   Nokia Symbian Series 60
●   Android – Scripting Layer for Android
●   Blackberry
●   Kivy – cross-platform: iOS, Android, Linux,
    Windows, Mac
Python Basics
●   The interpreter
    –   Installation
    –   Windows (set path)
●   Datatypes: int, str, float, lists, tuples,
    dictionaries
●   Basic I/O
Python Basics
●   Variables
    –   Dynamically-typed vs statically-typed
          >>> x = 1
          >>>y = “hello”
    –   Strongly-typed
          >>> x + y
●   Type function
          >>> type(x)
●   Integer vs float
          >>> z = 1.0
Python Basics

Operator          Operation

+                 Addition

-                 Subtraction

/                 Division

*                 Multiplication

**                Power

%                 Modulus
Python Basics

●   How will this be evaluated?
        >>>X = 1 + 2 – 3 ** 4 * ( 5+6)
Python Basics
●   Operator Precedence rules
    Parenthesis
    Power
    Multiplication
    Addition
    Left-to-right
Python Basics
●   Integer division
         >>> 4/2
         >>> 5/2
●   Mixing integer and floats
         >>> 5/2.0
●   Casting between integer and floats
         >>> float(5)
         >>>int(5.0)
Python Basics
    Strings – sequence of characters
         >>> s = “hello world”
●   Looking inside
         >>> s[0]
●   Concatenation
         >>> s = ”hello ” + “world”
●   Finding length
         >>> len(s)
●   Slicing
         >>> s = s[0:5]
Python Basics
    Handy String functions
●   find
           >>> s.find('e')
●   Replace
           >>> n = s.replace('e', 'a' )
●   Make upper, lower
           >>> u = s.upper()
Python Basics

●   Get the second word 'world' by slicing
        >>> “hello, world”[x:y]
Python Basics
    Lists – collection of values
●   Declaring
        >>> l = list()
        >>> l = []
●   Can hold different types
        >>> l = [1, 'a', [2, 3], 4]
        >>> l[2]
●   Appending
        >>> l.append('an item')
        >>>del(l[2])
Python Basics
    Lists – collection of values
●   Getting length
         >>> len(l)
●   Slicing
         >>> l[1:4]
●   Converting between strings and lists
         >>> strlist = “this is a string”.split('s')
         >>> “z”.join(strlist)
Python Basics

●   Append an item to the list within the list
         >>> l = [1, 'a', [2, 3], 4]
         >>> l = [1, 'a', [2, 3, 5], 4]
Python Basics
●   Handy functions
    Sum
          >>> sum([2, 3, 4])
    Max
          >>> max([2, 3, 4])
    Min
          >>> min([2, 3, 4])
Python Basics
    Dictionaries – key, value pairs
    Associative array, hash table
●   Declaring
        >>> d = dict()
        >>> d = {}
●   Setting a value
        >>> d[“event”] = “bootcamp”
        >>> d = {“event” : “bootcamp” }
●   Getting a value
        >>> d[“event”]
Python Basics
    Mutability
●   Mutable – can change
    –   Lists, dictionary
●   Immutable – cannot change
    –   Strings, tuples
●   Try set, del..
Python Basics
    Casting – numbers and strings
●   Strings and numbers
        >>> int(“234”)
        >>> str(234)
Python Basics
●   Importing modules
         >>> import math
         >>> math.sqrt(4)
         >>> from math import sqrt
         >>> sqrt(4)
●   dir() function
         >>> dir(math)
Python Basics
●   Basic I/O
        >>> name = raw_input()
        >>> name = raw_input(“Name: “)
    Input numbers:
        >>>age = raw_input(“Age: “)
        >>>age = int(raw_input(“Age: “))
Modules
●   Interactive mode vs modules
●   Indentation
Boolean Values
●   True
           >>> 1 < 2
●   False
           >>> 1 > 2
●   Also evaluate to False:
      “”, [], {}, 0
Loops
●   While loop – while condition is true
         x=0
         while x < 10:
           print x
           x=x+1
●   For loop – loops over items
         words = ['this' , 'is', 'a', 'list']
         for w in words:
            print w
●   Loop over strings, dictionaries..
●   Range() function
         >>> range(3)
         >>> range(0, 10, 2)
Functions
●   Defining functions
        def say_hello():
          print “hello”
●   Calling functions
        say_hello()
●   Parameters
        def sub(a, b):
          s=a-b
          return s
        sub(b=3, a=2)
Functions
●   Commenting in Python
        def sub(a, b):
          d = a – b #subtracts b from a
          return d
●   Doc strings
        def sub(a, b):
           “””this functions takes in 2 integers and returns their
        difference”””
          d=a–b
          return d
File I/O
●   Writing to a file
         f = open('text.txt', 'wb')
         f.write('This is a line.n')
         f.close()
●   Reading a file
         f = open('text.txt', 'rb')
         stream = f.read()
         f.close()
Accessing the Web
●   Establishing a connection
    –   sockets
●   Requests and Responses
    –   GET, retrieve a webpage
    –   POST, save data
●   Download a webpage
          fopen = urllib.urlopen(“http://www.google.com”)
          data = fopen.read()
Demo

●   Web demo
●   Scientific computing
Next Steps
●   Intermediate topics:
    –   Classes and objects in Python
    –   Regular Expressions
    –   Exceptions etc

●   Python on Appengine
●   Python user group
Resources
●   Official Python Docs tutorial
      http://docs.python.org/2/tutorial/
●   A byte of Python
      http://www.swaroopch.com/notes/python/
●   Think like a Computer Scientist
      http://www.openbookproject.net/thinkcs/python/english2e/

More Related Content

What's hot

Comparing JVM languages
Comparing JVM languagesComparing JVM languages
Comparing JVM languages
Jose Manuel Ortega Candel
 
Python dictionary : past, present, future
Python dictionary: past, present, futurePython dictionary: past, present, future
Python dictionary : past, present, future
delimitry
 
Python internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvandPython internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvand
irpycon
 
Hammurabi
HammurabiHammurabi
Hammurabi
Mario Fusco
 
Python for Dummies
Python for DummiesPython for Dummies
Python for Dummies
Leonardo Jimenez
 
Initial Java Core Concept
Initial Java Core ConceptInitial Java Core Concept
Initial Java Core Concept
Rays Technologies
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011
Andrey Breslav
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
intelliyole
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
Mario Fusco
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML Personalization
Jacopo Mangiavacchi
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
Raji Engg
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
Francesco Bruni
 
C# - What's next
C# - What's nextC# - What's next
C# - What's next
Christian Nagel
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
Muthu Vinayagam
 
Kotlin, why?
Kotlin, why?Kotlin, why?
Kotlin, why?
Paweł Byszewski
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
Mario Fusco
 
OOP Core Concept
OOP Core ConceptOOP Core Concept
OOP Core Concept
Rays Technologies
 
Python Training
Python TrainingPython Training
Python Training
TIB Academy
 
Communicating State Machines
Communicating State MachinesCommunicating State Machines
Communicating State Machines
srirammalhar
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
Jongsoo Lee
 

What's hot (20)

Comparing JVM languages
Comparing JVM languagesComparing JVM languages
Comparing JVM languages
 
Python dictionary : past, present, future
Python dictionary: past, present, futurePython dictionary: past, present, future
Python dictionary : past, present, future
 
Python internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvandPython internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvand
 
Hammurabi
HammurabiHammurabi
Hammurabi
 
Python for Dummies
Python for DummiesPython for Dummies
Python for Dummies
 
Initial Java Core Concept
Initial Java Core ConceptInitial Java Core Concept
Initial Java Core Concept
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML Personalization
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
 
C# - What's next
C# - What's nextC# - What's next
C# - What's next
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
 
Kotlin, why?
Kotlin, why?Kotlin, why?
Kotlin, why?
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
 
OOP Core Concept
OOP Core ConceptOOP Core Concept
OOP Core Concept
 
Python Training
Python TrainingPython Training
Python Training
 
Communicating State Machines
Communicating State MachinesCommunicating State Machines
Communicating State Machines
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
 

Viewers also liked

UNIVERSITY OF NAIROBI PROJECT
UNIVERSITY OF NAIROBI PROJECTUNIVERSITY OF NAIROBI PROJECT
UNIVERSITY OF NAIROBI PROJECT
Wilfred Gatimu
 
Cloud computing in kenya
Cloud computing in kenyaCloud computing in kenya
Cloud computing in kenya
Tonny Omwansa
 
Mt. Everest-eLearning & Gamification Innovation-Keynote
Mt. Everest-eLearning & Gamification Innovation-KeynoteMt. Everest-eLearning & Gamification Innovation-Keynote
Mt. Everest-eLearning & Gamification Innovation-Keynote
Erwin E. Sniedzins
 
Ici final-project (Individual)
Ici final-project (Individual)Ici final-project (Individual)
Ici final-project (Individual)
Ong En
 
What Really Matters in The Digital Learning Project 2013
What Really Matters in The Digital Learning Project 2013What Really Matters in The Digital Learning Project 2013
What Really Matters in The Digital Learning Project 2013
Darren Kuropatwa
 
IoT Smart APIs using Nomos RuleX
IoT Smart APIs using Nomos RuleXIoT Smart APIs using Nomos RuleX
IoT Smart APIs using Nomos RuleX
Cliff Faurer
 

Viewers also liked (6)

UNIVERSITY OF NAIROBI PROJECT
UNIVERSITY OF NAIROBI PROJECTUNIVERSITY OF NAIROBI PROJECT
UNIVERSITY OF NAIROBI PROJECT
 
Cloud computing in kenya
Cloud computing in kenyaCloud computing in kenya
Cloud computing in kenya
 
Mt. Everest-eLearning & Gamification Innovation-Keynote
Mt. Everest-eLearning & Gamification Innovation-KeynoteMt. Everest-eLearning & Gamification Innovation-Keynote
Mt. Everest-eLearning & Gamification Innovation-Keynote
 
Ici final-project (Individual)
Ici final-project (Individual)Ici final-project (Individual)
Ici final-project (Individual)
 
What Really Matters in The Digital Learning Project 2013
What Really Matters in The Digital Learning Project 2013What Really Matters in The Digital Learning Project 2013
What Really Matters in The Digital Learning Project 2013
 
IoT Smart APIs using Nomos RuleX
IoT Smart APIs using Nomos RuleXIoT Smart APIs using Nomos RuleX
IoT Smart APIs using Nomos RuleX
 

Similar to Python bootcamp - C4Dlab, University of Nairobi

Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
Sushant Mane
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
Adam Getchell
 
Python lecture 03
Python lecture 03Python lecture 03
Python lecture 03
Tanwir Zaman
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
Lennart Regebro
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
Sumit Raj
 
Python intro
Python introPython intro
Python intro
Abhinav Upadhyay
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.ppt
VicVic56
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
Itzik Kotler
 
Intro
IntroIntro
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
g3_nittala
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developers
bennuttall
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
aeberspaecher
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
Sumit Raj
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
Daniel Greenfeld
 
Computer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .pptComputer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .ppt
RedenOriola
 
Python programming
Python programmingPython programming
Python programming
saroja20
 
Biopython: Overview, State of the Art and Outlook
Biopython: Overview, State of the Art and OutlookBiopython: Overview, State of the Art and Outlook
Biopython: Overview, State of the Art and Outlook
Asociación Argentina de Bioinformática y Biología Computacional
 
Functional python
Functional pythonFunctional python
Functional python
Jesué Junior
 

Similar to Python bootcamp - C4Dlab, University of Nairobi (20)

Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
Python lecture 03
Python lecture 03Python lecture 03
Python lecture 03
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
 
Python intro
Python introPython intro
Python intro
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.ppt
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Intro
IntroIntro
Intro
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developers
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Computer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .pptComputer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .ppt
 
Python programming
Python programmingPython programming
Python programming
 
Biopython: Overview, State of the Art and Outlook
Biopython: Overview, State of the Art and OutlookBiopython: Overview, State of the Art and Outlook
Biopython: Overview, State of the Art and Outlook
 
Functional python
Functional pythonFunctional python
Functional python
 

Python bootcamp - C4Dlab, University of Nairobi

  • 1. Python Bootcamp - C4Dlab SCI labs, University of Nairobi Nov 24th 2013 Kenny Rachuonyo
  • 2. Introduction to Python Features of Python ● Simplicity - pseudocode ● Free and Open Source - community ● High-level – no low-level mngt ● Interpreted – run from source ● Object-Oriented – simple to use ● Extensible – C/C++
  • 3. Features (cont.) ● Embeddable – games, graphics, ● Extensive Libraries (batteries included) – data compression, OS, Networking, Internet, Multimedia, Graphics
  • 4. Python in the Industry Web ● Google – Youtube, backend tasks.. ● Reddit – news aggregation site ● Disqus – commenting service ● Numerous web frameworks – django, Zope, webapp2, web.py, pyramid, flask
  • 5. Python in the Industry Desktop ● Games – Counterstrike, Civilization IV ● Cinema 4D – Graphics ● Dropbox ● GUI frameworks – PyGTK, PyQT,
  • 6. Python in the Industry Scientific Computing ● NASA ● Packages: Scipy, Numpy, Matplotlib,
  • 7. Python in the Industry Mobile ● Nokia Symbian Series 60 ● Android – Scripting Layer for Android ● Blackberry ● Kivy – cross-platform: iOS, Android, Linux, Windows, Mac
  • 8. Python Basics ● The interpreter – Installation – Windows (set path) ● Datatypes: int, str, float, lists, tuples, dictionaries ● Basic I/O
  • 9. Python Basics ● Variables – Dynamically-typed vs statically-typed >>> x = 1 >>>y = “hello” – Strongly-typed >>> x + y ● Type function >>> type(x) ● Integer vs float >>> z = 1.0
  • 10. Python Basics Operator Operation + Addition - Subtraction / Division * Multiplication ** Power % Modulus
  • 11. Python Basics ● How will this be evaluated? >>>X = 1 + 2 – 3 ** 4 * ( 5+6)
  • 12. Python Basics ● Operator Precedence rules Parenthesis Power Multiplication Addition Left-to-right
  • 13. Python Basics ● Integer division >>> 4/2 >>> 5/2 ● Mixing integer and floats >>> 5/2.0 ● Casting between integer and floats >>> float(5) >>>int(5.0)
  • 14. Python Basics Strings – sequence of characters >>> s = “hello world” ● Looking inside >>> s[0] ● Concatenation >>> s = ”hello ” + “world” ● Finding length >>> len(s) ● Slicing >>> s = s[0:5]
  • 15. Python Basics Handy String functions ● find >>> s.find('e') ● Replace >>> n = s.replace('e', 'a' ) ● Make upper, lower >>> u = s.upper()
  • 16. Python Basics ● Get the second word 'world' by slicing >>> “hello, world”[x:y]
  • 17. Python Basics Lists – collection of values ● Declaring >>> l = list() >>> l = [] ● Can hold different types >>> l = [1, 'a', [2, 3], 4] >>> l[2] ● Appending >>> l.append('an item') >>>del(l[2])
  • 18. Python Basics Lists – collection of values ● Getting length >>> len(l) ● Slicing >>> l[1:4] ● Converting between strings and lists >>> strlist = “this is a string”.split('s') >>> “z”.join(strlist)
  • 19. Python Basics ● Append an item to the list within the list >>> l = [1, 'a', [2, 3], 4] >>> l = [1, 'a', [2, 3, 5], 4]
  • 20. Python Basics ● Handy functions Sum >>> sum([2, 3, 4]) Max >>> max([2, 3, 4]) Min >>> min([2, 3, 4])
  • 21. Python Basics Dictionaries – key, value pairs Associative array, hash table ● Declaring >>> d = dict() >>> d = {} ● Setting a value >>> d[“event”] = “bootcamp” >>> d = {“event” : “bootcamp” } ● Getting a value >>> d[“event”]
  • 22. Python Basics Mutability ● Mutable – can change – Lists, dictionary ● Immutable – cannot change – Strings, tuples ● Try set, del..
  • 23. Python Basics Casting – numbers and strings ● Strings and numbers >>> int(“234”) >>> str(234)
  • 24. Python Basics ● Importing modules >>> import math >>> math.sqrt(4) >>> from math import sqrt >>> sqrt(4) ● dir() function >>> dir(math)
  • 25. Python Basics ● Basic I/O >>> name = raw_input() >>> name = raw_input(“Name: “) Input numbers: >>>age = raw_input(“Age: “) >>>age = int(raw_input(“Age: “))
  • 26. Modules ● Interactive mode vs modules ● Indentation
  • 27. Boolean Values ● True >>> 1 < 2 ● False >>> 1 > 2 ● Also evaluate to False: “”, [], {}, 0
  • 28. Loops ● While loop – while condition is true x=0 while x < 10: print x x=x+1 ● For loop – loops over items words = ['this' , 'is', 'a', 'list'] for w in words: print w ● Loop over strings, dictionaries.. ● Range() function >>> range(3) >>> range(0, 10, 2)
  • 29. Functions ● Defining functions def say_hello(): print “hello” ● Calling functions say_hello() ● Parameters def sub(a, b): s=a-b return s sub(b=3, a=2)
  • 30. Functions ● Commenting in Python def sub(a, b): d = a – b #subtracts b from a return d ● Doc strings def sub(a, b): “””this functions takes in 2 integers and returns their difference””” d=a–b return d
  • 31. File I/O ● Writing to a file f = open('text.txt', 'wb') f.write('This is a line.n') f.close() ● Reading a file f = open('text.txt', 'rb') stream = f.read() f.close()
  • 32. Accessing the Web ● Establishing a connection – sockets ● Requests and Responses – GET, retrieve a webpage – POST, save data ● Download a webpage fopen = urllib.urlopen(“http://www.google.com”) data = fopen.read()
  • 33. Demo ● Web demo ● Scientific computing
  • 34. Next Steps ● Intermediate topics: – Classes and objects in Python – Regular Expressions – Exceptions etc ● Python on Appengine ● Python user group
  • 35. Resources ● Official Python Docs tutorial http://docs.python.org/2/tutorial/ ● A byte of Python http://www.swaroopch.com/notes/python/ ● Think like a Computer Scientist http://www.openbookproject.net/thinkcs/python/english2e/