6. Write a python program to read a file, a.txt line by line and store it into a variable.
The output is:
Original file a.txt:
Welcome to
www.freelearningpoints.com
You can learn Python tutorials and
practice with exercises
Expected Answer:
['Welcome to\n', 'www.freelearningpoints.com\n', 'You can learn Python tutorials and\n', 'practice with exercises']
Sample Answer:
def read_file(file_name): with open (file_name, "r") as myfile: data=myfile.readlines() print(data) read_file('a.txt')
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)