Python 27
Python 27
PROGRAM
a=10
b=5
c=a+b
print("addition:",c)
d=5
e=3
f=d-e
print("subtraction:",f)
g=10
h=2
i=g//h
print("division:",i)
j=8
k=5
l=j*k
print("multiplication:",l)
m=20
n=5
o=m%n
print("modulus:",o)
OUTPUT:
PROGRAM
my_str='hello'
print(my_str)
print(my_str)
world of python"""
print(my_str)
print(my_str.upper())
print(my_str.lower())
print(my_str.find('llo'))
print(my_str.replace('hello','happy'))
print(my_str.split())
my_str1='this is my world'
my_str="harsha"
print(my_str+my_str1)
print(my_str*10)
rev_str="".join(reversed(my_str2))
if
my_str2==rev_str:
else:
count=0
if(letter=='i'):
count+=1
print(count,'letters found')
OUTPUT:
A). TUPLE
tuple1 = 1, 2, "Hello"
print(tuple1)
print(type(tuple1)) i, j, k = tuple1
print(i, j, k)
print(len(tuple1))
16]))
print(item)
OUTPUT:
B) SET
color_set.remove('yellow')
print(color_set)
color_set.discard('white')
print(color_set)
deleted_item = color_set.pop()
print(deleted_item) color_set.clear()
print(color_set)
del color_set
OUTPUT:
PROGRAM
iList = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
print('iList: ',iList)
print('first element: ',iList[0])
print('fourth element: ',iList[3])
print('iList elements from 0 to 4 index:',iList[0: 5])
print('3rd or -7th element:',iList[-7])
iList.append(111)
print('iList after append():',iList)
print('index of \'80\': ',iList.index(80))
iList.sort()
print('after sorting: ', iList);
OUTPUT:
4.IMPLEMENTATION OF DICTIONARY
PROGRAM
y={'arasu':23,'nivi':20,ammu:21,'tamil':22}
l=list(y.items())
l.sort()
l=list(y.items())
l.sort(reverse=True)
dict=dict(l)
print("Dictionary",dict)
OUTPUT:
print(i)
5: # Calculate square
print(number * number)
def user_check(choice):
if choice == 1:
print("Admin")
elif choice == 2:
print("Editor")
elif choice == 3:
print("Guest") else:
print("Wrong entry")
user_check(1)
user_check(2)
user_check(3)
user_check(4)
if password == "PYnative@#29":
print("Correct password")
else:
else:
else:
OUTPUT:
PROGRAM
import math
print(math.sqrt(25))
print(math.pi)
print(math.degrees(2))
print(math.radians(60))
print(math.sin(2))
print(math.cos(0.5))
print(math.tan(0.23))
print(math.factorial(4)) import
random
print(random.randint(0, 5))
print(random.random())
print(random.random() * 100)
print(date.fromtimestamp(454554))
OUTPUT:
8. FILE HANDLING
PROGRAM
F=open("drinks.dat","r")
count=0
while(True):
b=F.read(1)
if(b=='\n'):
count+=1
if(b==""):
break
print(b,end="")
F.close()
FILE: drinks.dat
Red Bull
Cafe Mocha
Americano
Coca Cola
Tea
OUTPUT:
PROGRAM
class Message(object):
def __init__(self):
self.msg=None
def assignValue(self):
self.msg="Hello welcome to python programming"
def getValue(self,str):
self.msg=str def
printValue(self):
print("msg=",self.msg)
M=Message()
print("value after init.the object...")
M.printValue(); M.assignValue();
print("value after assignValue()..")
M.printValue();
M.getValue("How are you?") print("value
after getValue()...")
M.printValue();
OUTPUT:
A) EXCEPTION HANDLING
import sys
randomList=['a',0,2]
for entry in randomList:
try:
print("The entry is",entry)
r=1/int(entry)
break except:
print("Oops!",sys.exc_info()[0],"occured.")
print("Next entry.") print()
print("The reciprocal of",entry,"is",r)
OUTPUT:
B)REGULAR EXPRESSIONS
OUTPUT: