Program 11: Read and Write into a file # Program to show various ways to read and write data in a text file. # File Operations: Read Only ('r’), Read and Write ('r+’), Write Only ('w’), # Write and Read ('w+’), Append Only ('a’), Append and Read (‘a+’) file = open("E:\klcnew.txt","w") L = ['This is BCA College \n', 'Place is Nidasoshi \n', 'Fourth semester \n'] # assigned this ["This is BCA College \n", "Place is Nidasoshi \n", "Fourth semester \n"] to variable L file.write("Hello Python \n") file.writelines(L) file.close() # use the close() to change file access modes file = open("E:\klcnew.txt","r+") print("Output of the Read function is ") print(file.read()) print() # The seek(n) takes the file handle to the nth byte from the start. file.seek(0) print( "The output of the Readline function is ") print(file.readline()) print() SNJPSNMS Trust’s Degree College,Nidasoshi Python Programming Lab file.seek(0) # To show difference between read and readline print("Output of Read(12) function is ") print(file.read(12)) print() file.seek(0) print("Output of Readline(8) function is ") print(file.readline(8)) file.seek(0) # readlines function print("Output of Readlines function is ") print(file.readlines()) print() file.close()