SlideShare une entreprise Scribd logo
1  sur  99
Python – An Introduction
           Arulalan.T
           arulalant@gmail.com
           Centre for Atmospheric Science 
           Indian Institute of Technology Delhi
Python is a Programming Language
There are so many 
Programming Languages.




     Why Python      ?
Python is simple and beautiful
Python is Easy to Learn
Python is Free Open Source Software
Can Do
Text Handling             Games
System Administration     NLP
GUI programming
Web Applications          ...
Database Apps
Scientific Applications
  H i s t o r y
Guido van Rossum 
  Father of Python 
           1991
                 Perl  Java  Python   Ruby    PHP
            1987       1991           1993      1995
What is
Python?
Python is...


             A dynamic,open source
programming language with a focus on
simplicity and productivity.   It has an
  elegant syntax that is natural to
       read and easy to write.
Quick and Easy

Intrepreted Scripting Language

Variable declarations are unnecessary

Variables are not typed

Syntax is simple and consistent

Memory management is automatic
     Object Oriented Programming
      
      Classes
         Methods

         Inheritance

         Modules

         etc.,
  
    Examples!
print    “Hello World”
         No Semicolons !
         Indentation
You have to follow 
the Indentation 
Correctly.

Otherwise,

Python will beat 
you !
 Discipline 

   Makes  

    Good 
          Variables


  colored_index_cards
No Need to Declare Variable Types !




      Python Knows Everything !
value = 10

print value

value = 100.50

print value

value = “This is String”

print      value * 3
Input
name = raw_input(“What   is Your name?”)




print "Hello" , name , "Welcome"
Flow
if  score >= 5000 :
  print “You win!”
elif score <= 0 :
  print “Game over.”
else:
  print “Current score:”,score

print “Donen”
  Loop
for  i   in   range(1, 5):
        print    i
else:
        print    'The for loop is over'
number = 23
running = True
while running :
        guess = int(raw_input('Enter an integer : '))
        if  guess == number :
                print 'Congratulations, you guessed it.'
                running = False 
        elif  guess < number :
                print 'No, it is a little higher than that.'
        else:
                print 'No, it is a little lower than that.'

print  'Done'
Array
                List = Array


numbers = [ "zero", "one", "two", "three", 
"FOUR" ]  
                List = Array

numbers = [ "zero", "one", "two", "three", 
"FOUR" ]

numbers[0]
>>> zero 

numbers[4]                                 numbers[­1]
>>> FOUR                                  >>> FOUR
                         numbers[­2]
                          >>> three
  Multi Dimension List


numbers = [ ["zero", "one"],["two", "three", 
"FOUR" ]]

numbers[0]
>>> ["zero", "one"] 

numbers[0][0]                       numbers[­1][­1]
>>> zero                                  >>> FOUR
                         len(numbers)
                          >>> 2
                Sort List


primes = [ 11, 5, 7, 2, 13, 3 ]
                Sort List


primes = [ 11, 5, 7, 2, 13, 3 ]


primes.sort()
                Sort List


primes = [ 11, 5, 7, 2, 13, 3 ]


primes.sort()


>>> [2, 3, 5, 7, 11, 13]
                Sort List

names = [ "Shrini", "Bala", "Suresh",
"Arul"]

names.sort()

>>> ["Arul", "Bala","Shrini","Suresh"]

names.reverse()

>>> ["Suresh","Shrini","Bala","Arul"]
                Mixed List

names = [ "Shrini", 10, "Arul", 75.54]


names[1]+10
>>> 20


names[2].upper()

>>> ARUL
                Mixed List

names = [ "Shrini", 10, "Arul", 75.54]


names[1]+10
>>> 20


names[2].upper()

>>> ARUL
         Append on List


numbers = [ 1,3,5,7]

numbers.append(9)

>>> [1,3,5,7,9]
    Tuples
                                                             immutable
names = ('Arul','Dhastha','Raj')

name.append('Selva')

Error : Can not modify the tuple

Tuple is immutable type
    String
name = 'Arul'

name[0]
>>>'A'


myname = 'Arul' + 'alan'
>>> 'Arulalan'
split
name = 'This is python string'

name.split(' ')
>>>['This','is','python','string']

comma = 'Shrini,Arul,Suresh'

comma.split(',')
>>> ['Shrini','Arul','Suresh']
join
li = ['a','b','c','d']
s = '­'

new = s.join(li)
>>> a­b­c­d

new.split('­')
>>>['a','b','c','d']
'small'.upper()
>>>'SMALL'

'BIG'.lower()
>>> 'big'

'mIxEd'.swapcase()
>>>'MiXwD'
Dictionary
menu = {
  “idly”        :   2.50,
  “dosai”       :   10.00,
  “coffee”      :   5.00,
  “ice_cream”   :   5.00,
   100          :   “Hundred”
}

menu[“idly”]
2.50

menu[100]
Hundred
      Function
def sayHello():
        print 'Hello World!' # block belonging of fn
# End of function

sayHello() # call the function
def printMax(a, b):
        if a > b:
                print a, 'is maximum'
        else:
                print b, 'is maximum'
printMax(3, 4) 
Using in built Modules
#!/usr/bin/python
# Filename: using_sys.py
import time

print 'The sleep started'
time.sleep(3)
print 'The sleep finished'
#!/usr/bin/python
import os

os.listdir('/home/arulalan')

os.walk('/home/arulalan')
Making Our Own Modules
#!/usr/bin/python
# Filename: mymodule.py
def sayhi():
        print “Hi, this is mymodule speaking.”
version = '0.1'

# End of mymodule.py
#!/usr/bin/python
# Filename: mymodule_demo.py

import mymodule

mymodule.sayhi()
print 'Version', mymodule.version
#!/usr/bin/python
# Filename: mymodule_demo2.py
from mymodule import sayhi, version
# Alternative:                 
# from mymodule import *

sayhi()
print 'Version', version
Class
Classes

class Person:
        pass # An empty block

p = Person()

print p
Classes

class Person:
        def sayHi(self):
                print 'Hello, how are you?'

p = Person()

p.sayHi()
Classes
class Person:
        def __init__(self, name):
                #like contstructor                
                self.name = name
        def sayHi(self):
                print 'Hello, my name is', self.name

p = Person('Arulalan.T')

p.sayHi()
Classes


                            
Inheritance
Classes
class A:
        def  hello(self):
              print  ' I am super class '
class B(A):
         def  bye(self):
              print  ' I am sub class '

p = B()
p.hello()
p.bye()
Classes
class A:
        Var = 10
        def  __init__(self):
             self.public = 100
             self._protected_ = 'protected'
             self.__private__ = 'private'

Class B(A):
     pass
p = B()
p.__protected__
File Handling
File Writing
poem = ''' Programming is fun
When the work is done
if you wanna make your work also fun:
        use Python!
'''

f = file('poem.txt', 'w') # open for 'w'riting
f.write(poem) # write text to file
f.close() 
File Reading
f= file('poem.txt','r') 
for line in f.readlines():
   print line
f.close() 
           Database Intergration
import psycopg2
   

conn = psycopg2.connect(" dbname='pg_database' 
user='dbuser' host='localhost' password='dbpass' ")

cur = conn.cursor()
cur.execute("""SELECT * from pg_table""")
rows = cur.fetchall()
print rows

cur.close()
conn.close()
import psycopg2
   

conn = psycopg2.connect(" dbname='pg_database' 
user='dbuser' host='localhost' password='dbpass' ")

cur = conn.cursor()
cur.execute("'insert into pg_table values(1,'python')"')
conn.commit()

cur.close()
conn.close()
THE END
                                                    of code :­)
How to learn ?
                                     
               
Python – Shell
Interactive Python
                                              
Instance Responce
                        
Learn as you type
bpython
ipython        }  
                     teach you very easily




                                     
               
Python can communicate 
                 With
                Other
            Languages
           C
           +
       Python
        Java
           +
       Python
     GUI
        With 
   Python
                 Glade
                    +
                Python
                    +
                 GTK
                    = 
             GUI APP
GLADE
Using Glade + Python
Web
Web
        Web Frame Work in Python
Python an-intro - odp
Python an-intro - odp
Python an-intro - odp
Python an-intro - odp

Contenu connexe

En vedette

Pygrib documentation
Pygrib documentationPygrib documentation
Pygrib documentation
Arulalan T
 
TheAssociationOfAtheismOnLegalPersonalityInTurkey
TheAssociationOfAtheismOnLegalPersonalityInTurkeyTheAssociationOfAtheismOnLegalPersonalityInTurkey
TheAssociationOfAtheismOnLegalPersonalityInTurkey
Morgan Elizabeth Romano
 

En vedette (12)

Pygrib documentation
Pygrib documentationPygrib documentation
Pygrib documentation
 
TheAssociationOfAtheismOnLegalPersonalityInTurkey
TheAssociationOfAtheismOnLegalPersonalityInTurkeyTheAssociationOfAtheismOnLegalPersonalityInTurkey
TheAssociationOfAtheismOnLegalPersonalityInTurkey
 
Nltk - Boston Text Analytics
Nltk - Boston Text AnalyticsNltk - Boston Text Analytics
Nltk - Boston Text Analytics
 
Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
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
 
Unutturulmak istenen Devrimci Atatürk! (2)
Unutturulmak istenen Devrimci Atatürk! (2)Unutturulmak istenen Devrimci Atatürk! (2)
Unutturulmak istenen Devrimci Atatürk! (2)
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

Similaire à Python an-intro - odp

Python An Intro
Python An IntroPython An Intro
Python An Intro
Arulalan T
 
beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdf
ElNew2
 

Similaire à Python an-intro - odp (20)

python-an-introduction
python-an-introductionpython-an-introduction
python-an-introduction
 
Lesson1 python an introduction
Lesson1 python an introductionLesson1 python an introduction
Lesson1 python an introduction
 
Python An Intro
Python An IntroPython An Intro
Python An Intro
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Python introduction 2
Python introduction 2Python introduction 2
Python introduction 2
 
Python_in_Detail
Python_in_DetailPython_in_Detail
Python_in_Detail
 
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
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
 
Python Workshop
Python  Workshop Python  Workshop
Python Workshop
 
Python introduction 1
Python introduction 1  Python introduction 1
Python introduction 1
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
Python Novice to Ninja
Python Novice to NinjaPython Novice to Ninja
Python Novice to Ninja
 
2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf
 
python cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learningpython cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learning
 
Beginner's Python Cheat Sheet
Beginner's Python Cheat SheetBeginner's Python Cheat Sheet
Beginner's Python Cheat Sheet
 
beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdf
 
Python 101 1
Python 101   1Python 101   1
Python 101 1
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
 
1. python
1. python1. python
1. python
 
Python cheatsheet for beginners
Python cheatsheet for beginnersPython cheatsheet for beginners
Python cheatsheet for beginners
 

Plus de Arulalan T

Python an-intro-python-month-2013
Python an-intro-python-month-2013Python an-intro-python-month-2013
Python an-intro-python-month-2013
Arulalan T
 
Python an-intro v2
Python an-intro v2Python an-intro v2
Python an-intro v2
Arulalan T
 
Final review contour
Final review  contourFinal review  contour
Final review contour
Arulalan T
 
Contour Ilugc Demo Presentation
Contour Ilugc Demo Presentation Contour Ilugc Demo Presentation
Contour Ilugc Demo Presentation
Arulalan T
 
Contour Ilugc Demo Presentation
Contour Ilugc Demo PresentationContour Ilugc Demo Presentation
Contour Ilugc Demo Presentation
Arulalan T
 
Edit/correct India Map In Cdat Documentation - With Edited World Map Data
Edit/correct India Map In Cdat  Documentation -  With Edited World Map Data Edit/correct India Map In Cdat  Documentation -  With Edited World Map Data
Edit/correct India Map In Cdat Documentation - With Edited World Map Data
Arulalan T
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guide
Arulalan T
 
Automatic B Day Remainder Program
Automatic B Day Remainder ProgramAutomatic B Day Remainder Program
Automatic B Day Remainder Program
Arulalan T
 
Sms frame work using gnokii, ruby & csv - command line argument
Sms frame work using gnokii, ruby & csv - command line argument Sms frame work using gnokii, ruby & csv - command line argument
Sms frame work using gnokii, ruby & csv - command line argument
Arulalan T
 
sms frame work
sms frame worksms frame work
sms frame work
Arulalan T
 

Plus de Arulalan T (20)

wgrib2
wgrib2wgrib2
wgrib2
 
Climate Data Operators (CDO)
Climate Data Operators (CDO)Climate Data Operators (CDO)
Climate Data Operators (CDO)
 
CDAT - graphics - vcs - xmgrace - Introduction
CDAT - graphics - vcs - xmgrace - Introduction CDAT - graphics - vcs - xmgrace - Introduction
CDAT - graphics - vcs - xmgrace - Introduction
 
CDAT - cdms2, maskes, cdscan, cdutil, genutil - Introduction
CDAT - cdms2, maskes, cdscan, cdutil, genutil - Introduction CDAT - cdms2, maskes, cdscan, cdutil, genutil - Introduction
CDAT - cdms2, maskes, cdscan, cdutil, genutil - Introduction
 
CDAT - cdms numpy arrays - Introduction
CDAT - cdms numpy arrays - IntroductionCDAT - cdms numpy arrays - Introduction
CDAT - cdms numpy arrays - Introduction
 
Python an-intro-python-month-2013
Python an-intro-python-month-2013Python an-intro-python-month-2013
Python an-intro-python-month-2013
 
Python an-intro v2
Python an-intro v2Python an-intro v2
Python an-intro v2
 
Thermohaline Circulation & Climate Change
Thermohaline Circulation & Climate ChangeThermohaline Circulation & Climate Change
Thermohaline Circulation & Climate Change
 
Testing in-python-and-pytest-framework
Testing in-python-and-pytest-frameworkTesting in-python-and-pytest-framework
Testing in-python-and-pytest-framework
 
Final review contour
Final review  contourFinal review  contour
Final review contour
 
Contour Ilugc Demo Presentation
Contour Ilugc Demo Presentation Contour Ilugc Demo Presentation
Contour Ilugc Demo Presentation
 
Contour Ilugc Demo Presentation
Contour Ilugc Demo PresentationContour Ilugc Demo Presentation
Contour Ilugc Demo Presentation
 
Edit/correct India Map In Cdat Documentation - With Edited World Map Data
Edit/correct India Map In Cdat  Documentation -  With Edited World Map Data Edit/correct India Map In Cdat  Documentation -  With Edited World Map Data
Edit/correct India Map In Cdat Documentation - With Edited World Map Data
 
Nomography
NomographyNomography
Nomography
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guide
 
"contour.py" module
"contour.py" module"contour.py" module
"contour.py" module
 
contour analysis and visulaization documetation -1
contour analysis and visulaization documetation -1contour analysis and visulaization documetation -1
contour analysis and visulaization documetation -1
 
Automatic B Day Remainder Program
Automatic B Day Remainder ProgramAutomatic B Day Remainder Program
Automatic B Day Remainder Program
 
Sms frame work using gnokii, ruby & csv - command line argument
Sms frame work using gnokii, ruby & csv - command line argument Sms frame work using gnokii, ruby & csv - command line argument
Sms frame work using gnokii, ruby & csv - command line argument
 
sms frame work
sms frame worksms frame work
sms frame work
 

Dernier

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Dernier (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 

Python an-intro - odp