SlideShare a Scribd company logo
Python – An Introduction
           Arulalan.T
           arulalant@gmail.com
           Centre for Atmospheric Sciences 
           Indian Institute of Technology Delhi
Python is a Programming Language
There are so many 
Programming Languages.




     Why Python      ?
Lesson1 python an introduction
Lesson1 python an introduction
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!
Lesson1 python an introduction
print    “Hello World”
         No Semicolons !
         Indentation
You have to follow 
the Indentation 
Correctly.

Otherwise,

Python will beat 
you !
Lesson1 python an introduction
 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

while True :
        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
Lesson1 python an introduction
        Java
           +
       Python
Lesson1 python an introduction
     GUI
        With 
   Python
Lesson1 python an introduction
                 Glade
                    +
                Python
                    +
                 GTK
                    = 
             GUI APP
GLADE
Using Glade + Python
Web
Web
        Web Frame Work in Python
Lesson1 python an introduction
Lesson1 python an introduction
Lesson1 python an introduction
Lesson1 python an introduction

More Related Content

PDF
Python - An Introduction
Eueung Mulyana
 
PDF
Python Tutorial
Eueung Mulyana
 
PPT
Python ppt
Rohit Verma
 
PDF
Introduction to advanced python
Charles-Axel Dein
 
PPTX
Introduction to Python programming
Damian T. Gordon
 
ODP
Introduction to Python - Training for Kids
Aimee Maree
 
PDF
Python for Linux System Administration
vceder
 
PDF
An introduction to Python for absolute beginners
Kálmán "KAMI" Szalai
 
Python - An Introduction
Eueung Mulyana
 
Python Tutorial
Eueung Mulyana
 
Python ppt
Rohit Verma
 
Introduction to advanced python
Charles-Axel Dein
 
Introduction to Python programming
Damian T. Gordon
 
Introduction to Python - Training for Kids
Aimee Maree
 
Python for Linux System Administration
vceder
 
An introduction to Python for absolute beginners
Kálmán "KAMI" Szalai
 

What's hot (20)

ODP
OpenGurukul : Language : Python
Open Gurukul
 
PDF
Python programming Workshop SITTTR - Kalamassery
SHAMJITH KM
 
PPTX
Python
Gagandeep Nanda
 
PDF
AmI 2017 - Python basics
Luigi De Russis
 
PPTX
Programming in Python
Tiji Thomas
 
PPTX
Python for Beginners(v1)
Panimalar Engineering College
 
PDF
Python basic
Saifuddin Kaijar
 
ODP
Programming Under Linux In Python
Marwan Osman
 
PDF
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
PPTX
Python 101: Python for Absolute Beginners (PyTexas 2014)
Paige Bailey
 
PDF
Python made easy
Abhishek kumar
 
PDF
Python for-unix-and-linux-system-administration
Victor Marcelino
 
PPT
python.ppt
shreyas_test_1234
 
PPTX
Python in 30 minutes!
Fariz Darari
 
PPTX
Intro to Python Programming Language
Dipankar Achinta
 
ODP
An Intro to Python in 30 minutes
Sumit Raj
 
PPTX
Pythonppt28 11-18
Saraswathi Murugan
 
ODP
OpenGurukul : Language : PHP
Open Gurukul
 
PDF
Functions
Marieswaran Ramasamy
 
PPT
programming with python ppt
Priyanka Pradhan
 
OpenGurukul : Language : Python
Open Gurukul
 
Python programming Workshop SITTTR - Kalamassery
SHAMJITH KM
 
AmI 2017 - Python basics
Luigi De Russis
 
Programming in Python
Tiji Thomas
 
Python for Beginners(v1)
Panimalar Engineering College
 
Python basic
Saifuddin Kaijar
 
Programming Under Linux In Python
Marwan Osman
 
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Paige Bailey
 
Python made easy
Abhishek kumar
 
Python for-unix-and-linux-system-administration
Victor Marcelino
 
python.ppt
shreyas_test_1234
 
Python in 30 minutes!
Fariz Darari
 
Intro to Python Programming Language
Dipankar Achinta
 
An Intro to Python in 30 minutes
Sumit Raj
 
Pythonppt28 11-18
Saraswathi Murugan
 
OpenGurukul : Language : PHP
Open Gurukul
 
programming with python ppt
Priyanka Pradhan
 
Ad

Viewers also liked (20)

PDF
Introduction to python
Yi-Fan Chu
 
PPT
Introduction to Python
Nowell Strite
 
PPTX
An Introduction To Python - Python Midterm Review
Blue Elephant Consulting
 
ODP
Python Ireland Feb '11 Talks: Introduction to Python
Python Ireland
 
PPT
Python Introduction
Mohammad Javad Beheshtian
 
PDF
Python - Lecture 1
Ravi Kiran Khareedi
 
PDF
Analysis of Fatal Utah Avalanches with Python. From Scraping, Analysis, to In...
Matt Harrison
 
PPTX
Introduction to Advanced Javascript
Collaboration Technologies
 
PDF
Meetup Python Nantes - les tests en python
Arthur Lutz
 
PDF
Learning notes of r for python programmer (Temp1)
Chia-Chi Chang
 
PDF
Java OOP Programming language (Part 1) - Introduction to Java
OUM SAOKOSAL
 
PDF
PyCon 2013 : Scripting to PyPi to GitHub and More
Matt Harrison
 
PPT
Operator Overloading
Sardar Alam
 
PDF
Python for All
Pragya Goyal
 
PDF
Installing Python on Mac
Wei-Wen Hsu
 
PDF
Python master class part 1
Chathuranga Bandara
 
PDF
Introduction to facebook java script sdk
Yi-Fan Chu
 
DOCX
Introduction to Python - Running Notes
RajKumar Rampelli
 
PPTX
Mastering python lesson2
Ruth Marvin
 
PDF
Introduction to facebook javascript sdk
Yi-Fan Chu
 
Introduction to python
Yi-Fan Chu
 
Introduction to Python
Nowell Strite
 
An Introduction To Python - Python Midterm Review
Blue Elephant Consulting
 
Python Ireland Feb '11 Talks: Introduction to Python
Python Ireland
 
Python Introduction
Mohammad Javad Beheshtian
 
Python - Lecture 1
Ravi Kiran Khareedi
 
Analysis of Fatal Utah Avalanches with Python. From Scraping, Analysis, to In...
Matt Harrison
 
Introduction to Advanced Javascript
Collaboration Technologies
 
Meetup Python Nantes - les tests en python
Arthur Lutz
 
Learning notes of r for python programmer (Temp1)
Chia-Chi Chang
 
Java OOP Programming language (Part 1) - Introduction to Java
OUM SAOKOSAL
 
PyCon 2013 : Scripting to PyPi to GitHub and More
Matt Harrison
 
Operator Overloading
Sardar Alam
 
Python for All
Pragya Goyal
 
Installing Python on Mac
Wei-Wen Hsu
 
Python master class part 1
Chathuranga Bandara
 
Introduction to facebook java script sdk
Yi-Fan Chu
 
Introduction to Python - Running Notes
RajKumar Rampelli
 
Mastering python lesson2
Ruth Marvin
 
Introduction to facebook javascript sdk
Yi-Fan Chu
 
Ad

Similar to Lesson1 python an introduction (20)

PDF
Python An Intro
Arulalan T
 
ODP
Python an-intro - odp
Arulalan T
 
PPTX
python-an-introduction
Shrinivasan T
 
PDF
Becoming a Pythonist
Raji Engg
 
PPTX
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
PDF
Python Novice to Ninja
Al Sayed Gamal
 
PDF
bv-python-einfuehrung aplication learn.pdf
Mohammadalhaboob2030
 
ODP
Hands on Session on Python
Sumit Raj
 
PDF
Learn 90% of Python in 90 Minutes
Matt Harrison
 
PDF
Python slide
Kiattisak Anoochitarom
 
PPTX
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
PPT
Function in Python [Autosaved].ppt
GaganvirKaur
 
PPTX
Python basics
RANAALIMAJEEDRAJPUT
 
PPTX
Python programming workshop session 1
Abdul Haseeb
 
PDF
Python 101 1
Iccha Sethi
 
PPTX
Chapter 2 Python Language Basics, IPython.pptx
SovannDoeur
 
PPTX
Keep it Stupidly Simple Introduce Python
SushJalai
 
PPTX
python beginner talk slide
jonycse
 
PPTX
Python Details Functions Description.pptx
2442230910
 
PDF
Python for scientific computing
Go Asgard
 
Python An Intro
Arulalan T
 
Python an-intro - odp
Arulalan T
 
python-an-introduction
Shrinivasan T
 
Becoming a Pythonist
Raji Engg
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
Python Novice to Ninja
Al Sayed Gamal
 
bv-python-einfuehrung aplication learn.pdf
Mohammadalhaboob2030
 
Hands on Session on Python
Sumit Raj
 
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Function in Python [Autosaved].ppt
GaganvirKaur
 
Python basics
RANAALIMAJEEDRAJPUT
 
Python programming workshop session 1
Abdul Haseeb
 
Python 101 1
Iccha Sethi
 
Chapter 2 Python Language Basics, IPython.pptx
SovannDoeur
 
Keep it Stupidly Simple Introduce Python
SushJalai
 
python beginner talk slide
jonycse
 
Python Details Functions Description.pptx
2442230910
 
Python for scientific computing
Go Asgard
 

More from Arulalan T (20)

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

Recently uploaded (20)

PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
Understanding operators in c language.pptx
auteharshil95
 
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PPTX
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PDF
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Understanding operators in c language.pptx
auteharshil95
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 

Lesson1 python an introduction