Enrol to start learning
Reading is open to everyone. Enrolling is free, and it is what unlocks the audio lessons, practice tests and progress tracking.
13.5.1. Opening and Reading
This section
Practice test
9 questions on this section. Wrong answers show you what to read again.
Sign up to take itWhole chapter
Revision test
Mixed questions from across the chapter. Your answers get marked.
Sign up to take itQuick
Flashcard drill
3 cards from this lesson. Good the night before a test.
Try these first
- 1.
What function is used to open a file in Python?
Hint
Think of the basic operation needed to access files.
- 2.
Which mode would you use to read from a file?
Hint
Consider what you would do if you want to see content.
- 3.
What does the
open()function do?- Opens an existing file
- Creates a new file
- Both A and B
Hint
Think about the versatility of file operations.
- 4.
True or False: It is unnecessary to close files that have been opened.
- True
- False
Hint
Consider what happens when resources are not managed.
- 5.
Write a Python program that opens a file, reads its content line by line, and prints each line with its line number.
Hint
Don't forget to use enumeration to track line numbers!
- 6.
Create a function that checks if a file exists before attempting to open it and reads its contents.
Hint
Utilize the os module for file existence checking.
Exercises
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
3 more questions available
Enrol freeQuiz
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
Get your answers marked and your progress tracked
Enrol freeChallenge Problems
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting