Reading and Writing Files Questions and Answers
Python Programming - Reading and Writing Files Questions with Answers help learners understand how to handle data in text or binary formats. These Python File Handling Questions are important for TCS, Infosys, and Bank PO exams to master file input and output operations
Reading and Writing Files
Showing 10 of
25 questions
1. Which function is used to open a file in Python?
- file_open()
- open()
- read_file()
- file()
3. Which mode creates a new file for writing and returns error if file exists?
- "w"
- "a"
- "x"
- "r"
4. Which method reads the entire content of a file as a string?
- readline()
- readall()
- read()
- get()
5. Which method reads one line from a file?
- read()
- readline()
- nextline()
- getline()
6. Which method returns all lines in a file as a list?
- read()
- readlines()
- getlines()
- lines()
8. What is the correct way to close a file in Python?
- file.close()
- close(file)
- file->close()
- close.file()