2. Write a python program to add text to a file and display the text in python.txt.
The output is:
Expected Answer:
Python Exercises
Python Tutorials
Sample Answer:
def read_file(file_name): from itertools import islice with open(file_name, "w") as myfile: myfile.write("Python Exercises\n") myfile.write("Python Tutorials") txt = open(file_name) print(txt.read()) read_file('python.txt')
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)