0% found this document useful (0 votes)
17 views44 pages

Python Class

Uploaded by

sai.national2635
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
17 views44 pages

Python Class

Uploaded by

sai.national2635
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 44

PYTHON

By MS SAIKUMAAR
Python’s Benevolent Dictator For Life

“Python is an experiment in how much freedom


program-mers need. Too much freedom and
nobody can read another's code; too little and
expressive-ness is endangered.”
- Guido van Rossum
Python is a popular programming language. It was created by Guido Van Rossum
Why Python:
> Simple syntax
> Length of code is small
> Complex problems can be solved eassily.

Features of Python:
> Simple to learn > Open source
> Portability > High level Interpreter
> OOPs > Standard libraries - nearly 200+

Difference between C , Java, C++ and Python


History
Invented in the Netherlands, early 90s by Guido van Rossum Python was
conceived in the late 1980s and its implementation was started in December
1989
Guido Van Rossum is fan of ‘Monty Python’s Flying Circus’, this is a
famous TV show in Netherlands
Named after Monty Python
Open sourced from the beginning
• Created in 1989 by Guido Van Rossum
• Python 1.0 released in 1994
• Python 2.0 released in 2000
• Python 3.0 released in 2008
• Python 2.7 is the recommended version
• 3.0 adoption will take a few years

7
National PG College
Development Environments
IDE
11. Jupitor
1. PyDev with Eclipse
2. Komodo
3. Emacs
4. Vim
5. TextMate
6. Gedit
7. Idle
8. PIDA (Linux)(VIM Based)
9.NotePad++ (Windows)
10.Pycharm
8
Web Frameworks
• Django
• Flask
• Pylons
• TurboGears
• Zope
• Grok

9
Applications of Python:

* Web & Internet Development


* Business Applications
* Desktop GUI Applications
* Artificial Intelligence
* Machine Learning.
* Image Processing Applications
* Games & 3D graphics
* Network Programming
* Database Access
Intr. To Python Interpreter:
Python Code Execution
Python’s traditional runtime execution model: source code you type is translated to
byte code, which is then run by the Python Virtual Machine. Your code is
automatically compiled, but then it is interpreted.

Source code extension is .py


Byte code extension is .pyc (compiled python code)
Installing Python
Python is pre-installed on most Unix systems, including Linux and MAC OS X

But for in Windows Operating Systems , user can download from the
https://www.python.org/downloads/
- from the above link download latest version of python IDE and install,
recent version is 3.4.1 but most of them uses version 2.7.7 only
After installing the Python
Ver#2.7.7, go to start menu then
click on python 2.7 in that one
you can select python (command
line) it is prompt with >>>
Assigning Values to Variables
Assignment values to variables:
1. Basic form : Ex: a=10 b=20 c=30 c=a+b+c
2. Tuple Assignment: Ex: x,y = (50,100)  print(‘x=‘ , x) print(‘y=‘,y)
3. List Assignment: Ex: x,y=[3,5]
4. Sequence Assignment: Ex: a,b,c=10,20,30

5. Extended Sequence Unpacking: p,*q=“Hello” * means multiple assign


print(p) – H printed
print(q) = e l l o printed (rest of chars)
6. Multiple target Assignments: Ex: a=b=c=d=0 check print

7. Argument Assignment: Ex: a+=10 b-=10 …..


Ex: a=input()
asking a value - 10
b=input()
asking b value – 20
print(a+b) - 1020 printed

It you want numeric value then


x=int(a) y=int(b) print(x+y) ----- 30
Ex: a=int(input())
then it will read numeric data

Ex: a=int(input(“Enter the value of a:”))


num=7
amt=123.45
code=‘A’
pi=3.14159
population=10000000000
msg=“Hi”

print(“Num = “+str(num))
Print(“\n AMT=“+str(amt))
print(“\n code=“+str(code))
print(“\n Population=“+str(population))
print(“\n Pi=“+str(pi))
print(“\n Message=“+str(msg))
a= [10.20.30] ---- 10 in a - True
Simple if: If – elif-else:
If - else:

If condition: If condition:
If condition:
True statement True statement1
True statement
Elif condition:
else:
True statement2
False statement
Ex: Else:
False statement
n = int(input()) Ex:
Ex:
n = int(input())
if n>0 : a=int(input("enter a value"))
if n>0 :
print("is positive") print("is positive") b=int(input("enter b value"))
else: if a>b :
print("is negative") print("a is big")
elif a<b:
print("a is small than b")
else :
print("both are equal")
Iterative / Loops: i=1 for i in range(0,5,1):
syntax: n=int(input("enter n value")) print(i)
while i<=n:
while condition: print(i) for i in range(5):
i=i+1 print(i)
block statements
str="PYTHON" List=[10,20,30,40,50]
for loop for l in str: for ele in List:
print(l) print(ele)
1. range function ---- for i in range(1,5):
for j in range(1,5):
range(start, stop, step) : print(i*j, end=" ")
print(" ")
Statements
default start=0 step=1 for i in range(10):
if i==5:
break
else:
2. sequence function ---- print(i)
sequence – using str,List,Tuple
Modules --- 1. Math module
2. Random module
Every math module function should start with

math and import math before using


Every random module function should start
with random and import random before using
Math.ceil(10.3)  11

a=[20,30,40]
Math.fsum(a)  90
Import random
K=[10,20,30]
random.choice(1) -- 10
a=List() / a=[comma separated values]
LISTS:
Ex: a=[10,20,30,40,50]
print(a) / print(a[0]) / print(a[1])

Allowed Forward access and backword access


Print(a[-1])

Slicing -- [start value : end value]


Ex: print(a[0:3]) ---- 10 20 30 print(a[:3]) ---- 10 20 30
print(a[:]) ---- 10 20 30 40 50 print(a[2:]) --- 30 40 50
Reassigning values:
a[2]=25 print(a) – 10 20 25
Multidim:
a=[ [10,20,30],[40,50,60]] - print(a) , print(a[0][0])
Basic operations:
+ , * , len, min, max, sum, membership, iterations
Ex: a=[10,20,30] b=[40,50,60]
a+b --- 10 20 30 40 50 60
Ex: a*2 (not a*b) len(a) min(a) max(a) sum(a)
Ex: for I in a: for I in range(len(a)):
print(i) print(a[i])
Built-in Methods:
a=list()
print a
DICTIONARY
LIBRARIES

You might also like