SlideShare a Scribd company logo
Python – An Introduction
Shrinivasan T
tshrinivasan@gmail.com
http://goinggnu.wordpress.com
Python is a Programming Language
There are so many
Programming
Languages.
Why Python?
python-an-introduction
python-an-introduction
Python is simple and beautiful
Python is Easy to Learn
Python is Free Open Source Software
Can Do
 Text Handling
 System Administration
 GUI programming
 Web Applications
 Database Apps
 Scientific Applications
 Games
 NLP
 ...
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!
python-an-introduction
print (“Hello World”)
No Semicolons !
Indentation
You have to follow the
Indentation
Correctly.
Otherwise,
Python will beat you !
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 = input(“What is Your name?”)
print("Hello" ,name , "Welcome")
Flow
score=int(input(“ type a number”))
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)
print('The for loop is over')
number = 23
running = True
while running :
guess = int(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()
>>> print(primes)
[2, 3, 5, 7, 11, 13]
Sort List
names = [ "Shrini", "Bala", "Suresh",
"Arul"]
names.sort()
print(names)
>>> ["Arul", "Bala","Shrini","Suresh"]
names.reverse()
print(names)
>>> ["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]
Tuplesimmutable
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'
name = 'This is python string'
name.split(' ')
>>>['This','is','python','string']
comma = 'Shrini,Arul,Suresh'
comma.split(',')
>>> ['Shrini','Arul','Suresh']
split
li = ['a','b','c','d']
s = '-'
new = s.join(li)
>>> a-b-c-d
new.split('-')
>>>['a','b','c','d']
join
'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
print(os.listdir('/home/arulalan'))
print(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
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__
Classes
File Handling
File Writing
poem = ''' Programming is fun
When the work is done
if you wanna make your work also fun:
use Python!
'''
f = open('poem.txt', 'w') # open for 'w'riting
f.write(poem) # write text to file
f.close()
File Reading
f= open('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
python-an-introduction
Java
+
Python
python-an-introduction
GUI
With
Python
python-an-introduction
Glade
+
Python
+
GTK
=
GUI APP
GLADE
Using Glade + Python
Web
We
b
Web Frame Work in Python
python-an-introduction
python-an-introduction
python-an-introduction
https://python.swaroopch.com/
Easiest free online book for
Python
python-an-introduction
python-an-introduction
python-an-introduction
Join ChennaiPy Mailing List and Ask/Answer questions
https://mail.python.org/mailman/listinfo/chennaipy
python-an-introduction
python-an-introduction

More Related Content

PDF
Adopting Java for the Serverless world at Serverless Meetup New York and Boston
PPT
SEKLUSI-RESTRAIN.ppt
DOC
97324197 parasit
DOCX
GAGAL JANTUNG KONGESTIF DAN HIPERTENSI
PPTX
PPTX
Perdarahan Saluran Cerna
PDF
Tesi Triennale - Ferioli Francesca
PPT
SPGDT Minggu 20 aug JAMBI.ppt
Adopting Java for the Serverless world at Serverless Meetup New York and Boston
SEKLUSI-RESTRAIN.ppt
97324197 parasit
GAGAL JANTUNG KONGESTIF DAN HIPERTENSI
Perdarahan Saluran Cerna
Tesi Triennale - Ferioli Francesca
SPGDT Minggu 20 aug JAMBI.ppt

What's hot (12)

PDF
Konsensus insulin
PDF
Memulai Data Processing dengan Spark dan Python
PPT
Gagal hati akut
PDF
ppt_Penatalaksanaan Syok (Adam_FIK UI)
PPTX
TERSEDAK.pptx
PDF
2. airway and breathing management 11
PPTX
Best Coding Practices in Java and C++
PDF
Kewaspadaan Isolasi.pdf
PDF
Manajemen Bencana Rumah Sakit
PPTX
Senyawa beta agonis pada produk asal ternak dan pengaruhnya
PPTX
Skenario Pucat
PPTX
Konsep dan prinsip kegawatdaruratan dalam keperawatan
Konsensus insulin
Memulai Data Processing dengan Spark dan Python
Gagal hati akut
ppt_Penatalaksanaan Syok (Adam_FIK UI)
TERSEDAK.pptx
2. airway and breathing management 11
Best Coding Practices in Java and C++
Kewaspadaan Isolasi.pdf
Manajemen Bencana Rumah Sakit
Senyawa beta agonis pada produk asal ternak dan pengaruhnya
Skenario Pucat
Konsep dan prinsip kegawatdaruratan dalam keperawatan
Ad

Similar to python-an-introduction (20)

ODP
Python an-intro - odp
PDF
Lesson1 python an introduction
PDF
Python An Intro
ODP
An Intro to Python in 30 minutes
PPTX
Session 02 python basics
PPTX
Session 02 python basics
PPTX
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
ODP
Introduction to Python3 Programming Language
PDF
Learn 90% of Python in 90 Minutes
PPTX
PPTX
Keep it Stupidly Simple Introduce Python
PDF
Python Part 1
PPTX
PYTHON.pptx
ODP
Programming Under Linux In Python
PPTX
python beginner talk slide
ODP
Hands on Session on Python
PPT
01-Python-Basics.ppt
PPTX
Introduction to learn and Python Interpreter
PDF
Python Novice to Ninja
PPTX
Python Workshop
Python an-intro - odp
Lesson1 python an introduction
Python An Intro
An Intro to Python in 30 minutes
Session 02 python basics
Session 02 python basics
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python3 Programming Language
Learn 90% of Python in 90 Minutes
Keep it Stupidly Simple Introduce Python
Python Part 1
PYTHON.pptx
Programming Under Linux In Python
python beginner talk slide
Hands on Session on Python
01-Python-Basics.ppt
Introduction to learn and Python Interpreter
Python Novice to Ninja
Python Workshop
Ad

More from Shrinivasan T (20)

PDF
Giving New Life to Old Tamil Little Magazines Through Digitization
PDF
Digitization of Tamil Soviet Publications and Little Magazines.pdf
PDF
Tamilinayavaani - integrating tva open-source spellchecker with python
PDF
Algorithms for certain classes of tamil spelling correction
PDF
Tamil and-free-software - தமிழும் கட்டற்ற மென்பொருட்களும்
ODP
Introducing FreeTamilEbooks
ODP
கணித்தமிழும் மென்பொருள்களும் - தேவைகளும் தீர்வுகளும்
ODP
Contribute to free open source software tamil - கட்டற்ற மென்பொருளுக்கு பங்களி...
ODP
ஏன் லினக்ஸ் பயன்படுத்த வேண்டும்? - Why Linux? in Tamil
ODP
கட்டற்ற மென்பொருள் பற்றிய அறிமுகம் - தமிழில் - Introduction to Open source in...
ODP
Share your knowledge in wikipedia
ODP
Open-Tamil Python Library for Tamil Text Processing
ODP
Version control-systems
ODP
Contribute to-ubuntu
PDF
Dhvani TTS
PDF
Freedom toaster
PDF
Sprit of Engineering
PDF
Amace ion newsletter-01
ODP
Rpm Introduction
PDF
Foss History
Giving New Life to Old Tamil Little Magazines Through Digitization
Digitization of Tamil Soviet Publications and Little Magazines.pdf
Tamilinayavaani - integrating tva open-source spellchecker with python
Algorithms for certain classes of tamil spelling correction
Tamil and-free-software - தமிழும் கட்டற்ற மென்பொருட்களும்
Introducing FreeTamilEbooks
கணித்தமிழும் மென்பொருள்களும் - தேவைகளும் தீர்வுகளும்
Contribute to free open source software tamil - கட்டற்ற மென்பொருளுக்கு பங்களி...
ஏன் லினக்ஸ் பயன்படுத்த வேண்டும்? - Why Linux? in Tamil
கட்டற்ற மென்பொருள் பற்றிய அறிமுகம் - தமிழில் - Introduction to Open source in...
Share your knowledge in wikipedia
Open-Tamil Python Library for Tamil Text Processing
Version control-systems
Contribute to-ubuntu
Dhvani TTS
Freedom toaster
Sprit of Engineering
Amace ion newsletter-01
Rpm Introduction
Foss History

Recently uploaded (20)

PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Complications of Minimal Access Surgery at WLH
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Complications of Minimal Access Surgery at WLH
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Orientation - ARALprogram of Deped to the Parents.pptx
01-Introduction-to-Information-Management.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Final Presentation General Medicine 03-08-2024.pptx
Supply Chain Operations Speaking Notes -ICLT Program
Microbial disease of the cardiovascular and lymphatic systems
STATICS OF THE RIGID BODIES Hibbelers.pdf
Weekly quiz Compilation Jan -July 25.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Yogi Goddess Pres Conference Studio Updates
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf

python-an-introduction