SlideShare a Scribd company logo
1 of 20
Download to read offline
Python



Python : An Introduction

       Kannappan S (mapquest, Aol.)
                 PyCon India 2010
History


●   Guido Van Rossum
●   1991
●   Python Software Foundation
●   python.org
Think !
“The real purpose of education is not the learning of facts but training the mind to think”

                                                              - Albert Einstein


WHAT DO YOU
           NEED
                      FROM A
                          PROGRAMMING LANGUAGE ?
Hello World
Data Types
    Python is dynamically typed
    Some important data types
●   int
●   float
●   strings
●   lists
●   dictionaries
Numerical Operations
●   >>> 5 + 3

    8
●   >>> 5 - 3

    2
●   >>> 5 * 3

    15
●   >>> 5 / 3

    2
●   >>> 5.0 / 3

    1.6666666666666667
Numerical Functions
●   >>> import math
●   >>> math.pow(5,3)

    125.0
●   >>> math.sqrt(25)

    5.0
●   >>> math.log(1024, 2)

    10.0
●   >>> math.factorial(5)

    120
Conditional Operations
●   >>> 5 == 5

    True
●   >>> 5 != 5

    False
●   >>> 5 > 3

    True
●   >>> 5 <= 3

    False
●   >>> 0 < 5 > 3 < 2

    False
Strings
●   compound data type
●   >>> company1 = 'Apple'
●   >>> company2 = 'Google'
●   >>> company1 + company2

    'AppleGoogle'
●   >>> company1[0]

    'A'
●   >>> company2[0:3] + company1[-2]

    'Gool'
String Functions
●   >>> import string
●   >>> 'Apple'.lower()

    'apple'
●   >>> 'Google'.upper()

    'GOOGLE'
●   >>> 'Apple'.replace('App', 'Peop')

    'People'
●   >>> 'Apple'.strip('e')

    'Appl'
Lists
●   workhorse of python
●   >>> companies = ['Apple', 'Google', 'Yahoo', 'Microsoft', 'AOL']
●   >>> len(companies)

    5
●   >>> companies[-1]

    'AOL'
●   >>> newcompanies = ['facebook', 'twitter']
●   >>> companies + newcompanies

    ['Apple', 'Google', 'Yahoo', 'Microsoft', 'AOL', 'facebook', 'twitter']
List Functions
●   >>> newcompanies.append('zynga')

    ['facebook', 'twitter', 'zynga']
●   >>> newcompanies.remove('facebook')

    ['twitter', 'zynga']
●   >>> newcompanies.index('twitter')

    0
●   >>> newcompanies.reverse()

    ['zynga', 'twitter']
●   >>> 'twitter' not in newcompanies

    False
Dictionaries
●   >>> english2french = {}
●   >>> english2french['hello'] = 'bonjour'
●   >>> english2french['goodbye'] = 'adieu'
●   >>> print english2french

    {'hello' : 'bonjour', 'goodbye' : 'adieu'}
●   >>> english2french['thanks'] = 'merci'
●   >>> len(english2french)

    3
●   >>> del english2french('goodbye')

    {'hello' : 'bonjour', 'thanks' : 'merci'}
Dictionary Functions
●   >>> english2french.keys()

    ['hello', 'thanks']
●   >>> english2french.values()

    ['bonjour', 'merci']
●   >>> english2french.items()

    [ ('hello', 'bonjour'), ('thanks', 'merci') ]
●   >>> english2french.has_key( 'love' )

    False
Loops
●   indentation is a must in python
●   >>> for i in range(2,4):

    ...        print i

    2

    3
●   >>> newcompanies = ['facebook', twitter']
●   >>> for company in newcompanies:

    ...        print company

    facebook

    twitter
Loops
>>> count = 1

>>> while count <= 5 :

...      print count

...      count += 1

1

2

3

4

5
Functions
●   >>> def addHundred(a):

    ...      return a + 100
●   >>> addHundred(8)

    108
●   >>> def summation(a,b):

    ...      return a+b
●   >>> summation(5,10)

    15
●   >>> def isOdd(a):

    ...      return a%2
Functional Aspects
●   >>> list1 = [16,23,36]
●   >>> map(addHundred, list1)

    [116, 123, 136]
●   >>> reduce(summation, list1)

    75
●   >>> filter(isOdd, list1)

    23
short program
#! /usr/bin/env python

# This program generates fibonacci sequence

def fib(n):

  if n == 0 or n == 1 :

     return n

  else :

     return fib(n-1) + fib(n-2)

if __name == “__main__”:

  for num in range(1,10) : print fib(num)



1 1 2 3 5 8 13 21 34
Links


●   How to think like a Computer Scientist
    http://www.greenteapress.com/thinkpython/thinkCSpy/


●   Google University Video
    http://code.google.com/edu/languages/google-python-class/

More Related Content

Viewers also liked

Viewers also liked (20)

Build and deploy scientific Python Applications
Build and deploy scientific Python Applications  Build and deploy scientific Python Applications
Build and deploy scientific Python Applications
 
Linux
Linux Linux
Linux
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
MySQL database
MySQL databaseMySQL database
MySQL database
 
Web 2 0 Ppt
Web 2 0 PptWeb 2 0 Ppt
Web 2 0 Ppt
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 
Mysql Ppt
Mysql PptMysql Ppt
Mysql Ppt
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Mysql an introduction
Mysql an introductionMysql an introduction
Mysql an introduction
 
MySQL Features & Implementation
MySQL Features & ImplementationMySQL Features & Implementation
MySQL Features & Implementation
 
MySQL DBA
MySQL DBAMySQL DBA
MySQL DBA
 
Quick Guide with Linux Command Line
Quick Guide with Linux Command LineQuick Guide with Linux Command Line
Quick Guide with Linux Command Line
 
Basic commands of linux
Basic commands of linuxBasic commands of linux
Basic commands of linux
 
Linux Basic Commands
Linux Basic CommandsLinux Basic Commands
Linux Basic Commands
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel Programming
 
Basic 50 linus command
Basic 50 linus commandBasic 50 linus command
Basic 50 linus command
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 

Similar to PythonIntro_pycon2010

Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobikrmboya
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with PythonSushant Mane
 
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 CSteffen Wenz
 
Introduction to Python3 Programming Language
Introduction to Python3 Programming LanguageIntroduction to Python3 Programming Language
Introduction to Python3 Programming LanguageTushar Mittal
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Fixing Web Data in Production
Fixing Web Data in ProductionFixing Web Data in Production
Fixing Web Data in ProductionAaron Knight
 
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
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on PythonSumit Raj
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdfCBJWorld
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesTatiana Al-Chueyr
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developersbennuttall
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfRamziFeghali
 
Python-GTK
Python-GTKPython-GTK
Python-GTKYuren Ju
 
Thinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonThinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonAnoop Thomas Mathew
 
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...DevDay.org
 

Similar to PythonIntro_pycon2010 (20)

Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
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
 
Python lecture 03
Python lecture 03Python lecture 03
Python lecture 03
 
Functional python
Functional pythonFunctional python
Functional python
 
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
 
Introduction to Python3 Programming Language
Introduction to Python3 Programming LanguageIntroduction to Python3 Programming Language
Introduction to Python3 Programming Language
 
Python 1
Python 1Python 1
Python 1
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Fixing Web Data in Production
Fixing Web Data in ProductionFixing Web Data in Production
Fixing Web Data in Production
 
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...
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummies
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developers
 
Sets in python
Sets in pythonSets in python
Sets in python
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdf
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Thinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonThinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in Python
 
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
 

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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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 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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

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...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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 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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

PythonIntro_pycon2010

  • 1. Python Python : An Introduction Kannappan S (mapquest, Aol.) PyCon India 2010
  • 2. History ● Guido Van Rossum ● 1991 ● Python Software Foundation ● python.org
  • 3. Think ! “The real purpose of education is not the learning of facts but training the mind to think” - Albert Einstein WHAT DO YOU NEED FROM A PROGRAMMING LANGUAGE ?
  • 5. Data Types Python is dynamically typed Some important data types ● int ● float ● strings ● lists ● dictionaries
  • 6. Numerical Operations ● >>> 5 + 3 8 ● >>> 5 - 3 2 ● >>> 5 * 3 15 ● >>> 5 / 3 2 ● >>> 5.0 / 3 1.6666666666666667
  • 7. Numerical Functions ● >>> import math ● >>> math.pow(5,3) 125.0 ● >>> math.sqrt(25) 5.0 ● >>> math.log(1024, 2) 10.0 ● >>> math.factorial(5) 120
  • 8. Conditional Operations ● >>> 5 == 5 True ● >>> 5 != 5 False ● >>> 5 > 3 True ● >>> 5 <= 3 False ● >>> 0 < 5 > 3 < 2 False
  • 9. Strings ● compound data type ● >>> company1 = 'Apple' ● >>> company2 = 'Google' ● >>> company1 + company2 'AppleGoogle' ● >>> company1[0] 'A' ● >>> company2[0:3] + company1[-2] 'Gool'
  • 10. String Functions ● >>> import string ● >>> 'Apple'.lower() 'apple' ● >>> 'Google'.upper() 'GOOGLE' ● >>> 'Apple'.replace('App', 'Peop') 'People' ● >>> 'Apple'.strip('e') 'Appl'
  • 11. Lists ● workhorse of python ● >>> companies = ['Apple', 'Google', 'Yahoo', 'Microsoft', 'AOL'] ● >>> len(companies) 5 ● >>> companies[-1] 'AOL' ● >>> newcompanies = ['facebook', 'twitter'] ● >>> companies + newcompanies ['Apple', 'Google', 'Yahoo', 'Microsoft', 'AOL', 'facebook', 'twitter']
  • 12. List Functions ● >>> newcompanies.append('zynga') ['facebook', 'twitter', 'zynga'] ● >>> newcompanies.remove('facebook') ['twitter', 'zynga'] ● >>> newcompanies.index('twitter') 0 ● >>> newcompanies.reverse() ['zynga', 'twitter'] ● >>> 'twitter' not in newcompanies False
  • 13. Dictionaries ● >>> english2french = {} ● >>> english2french['hello'] = 'bonjour' ● >>> english2french['goodbye'] = 'adieu' ● >>> print english2french {'hello' : 'bonjour', 'goodbye' : 'adieu'} ● >>> english2french['thanks'] = 'merci' ● >>> len(english2french) 3 ● >>> del english2french('goodbye') {'hello' : 'bonjour', 'thanks' : 'merci'}
  • 14. Dictionary Functions ● >>> english2french.keys() ['hello', 'thanks'] ● >>> english2french.values() ['bonjour', 'merci'] ● >>> english2french.items() [ ('hello', 'bonjour'), ('thanks', 'merci') ] ● >>> english2french.has_key( 'love' ) False
  • 15. Loops ● indentation is a must in python ● >>> for i in range(2,4): ... print i 2 3 ● >>> newcompanies = ['facebook', twitter'] ● >>> for company in newcompanies: ... print company facebook twitter
  • 16. Loops >>> count = 1 >>> while count <= 5 : ... print count ... count += 1 1 2 3 4 5
  • 17. Functions ● >>> def addHundred(a): ... return a + 100 ● >>> addHundred(8) 108 ● >>> def summation(a,b): ... return a+b ● >>> summation(5,10) 15 ● >>> def isOdd(a): ... return a%2
  • 18. Functional Aspects ● >>> list1 = [16,23,36] ● >>> map(addHundred, list1) [116, 123, 136] ● >>> reduce(summation, list1) 75 ● >>> filter(isOdd, list1) 23
  • 19. short program #! /usr/bin/env python # This program generates fibonacci sequence def fib(n): if n == 0 or n == 1 : return n else : return fib(n-1) + fib(n-2) if __name == “__main__”: for num in range(1,10) : print fib(num) 1 1 2 3 5 8 13 21 34
  • 20. Links ● How to think like a Computer Scientist http://www.greenteapress.com/thinkpython/thinkCSpy/ ● Google University Video http://code.google.com/edu/languages/google-python-class/