5. Write a python program to read a file, a.txt line by line.
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) as f: #Content_list is the list that contains the read lines. content_list = f.readlines() print(content_list) read_file('a.txt')
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)