Advance Python Programming Practicals Semester - 2
Advance Python Programming Practicals Semester - 2
i) #READ Operation:-
fo=open("C:/Users/ORISANLAB-23/Desktop/abc.txt","r+")
str=fo.read(10) print(str) fo.close()
Output:-
fo=open("C:/Users/ORISANLAB-23/Desktop/abc.txt","w")
fo.write("Hello Python")
print(fo)
fo.close()
Output:-
Practical No 2 :-
Aim :- Write A Python Program To Demonstrate Use Of Regular Expression
For Suitable Application.
Code :-
Output:-
import re
line = ‘Cats Are Smaller Than Dogs’
matchobj= re.match(r’cats’,line) if
matchobj:
print(“Match Found”) else
print(“Match Not Found”)
Output:-
Output :-
iv) Using search() Function:-
Output :-
Output :-
Output :-
Practical No 3 :-
Code :-
i) Single Threading :-
import threading, time def
Test(n):
i=1
while i <= n:
print("main
thread=", i)
i = i + 1
time.sleep(5) if __name__
== "__main__":
t1 = threading.Thread(target=Test,
args=(15,)) t1.start() t1.join()
Output :-
import threading
def print_cube(num):
print("Cube:", num * num * num)
def print_square(num):
print("Square:", num * num)
if __name__ == "__main__":
t1 = threading.Thread(target=print_square, args=(10,))
t2 = threading.Thread(target=print_cube,
args=(10,)) t1.start() t1.join() t2.start()
t2.join()
print("Done")
Output :-