Python Class
Python Class
By MS SAIKUMAAR
Python’s Benevolent Dictator For Life
Features of Python:
> Simple to learn > Open source
> Portability > High level Interpreter
> OOPs > Standard libraries - nearly 200+
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:
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
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
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])