0% found this document useful (0 votes)
2 views1 page

Text File Open

Uploaded by

alangiftson2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Text File Open

Uploaded by

alangiftson2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. What does the mode 'r' stand for in file handling?

a) Read b) Rename c) Remove d) Replace

2. Which mode is used to write to a file and erase existing content?


a) a b) r c) w d) r+

3. What happens if you open a non-existent file in 'r' mode?


a) File is created b) Returns empty string c) Error occurs d) File gets erased

4. The mode 'a' is used to:


a) Append data to an existing file b) Always create a new file
c) Read a file d) Delete content from a fi

5. What is the purpose of the mode 'w+'?


a) Only read b) Read and write c) Only write d) Append and read

6. Which of the following modes will create a file if it doesn't exist and give an error if it does?
a) 'a' b) 'w' c) 'r' d) 'n'

7. Which mode is used to read and write without erasing existing content?
a) 'w+' b) 'r+' c) 'a+' d) 'x+'

8. The 'a+' mode allows you to:


a) Read and write from the beginning b) Overwrite file completely
c) Append and read from end d) Delete the file

9. Which file mode allows both read and append operations?


a) 'r' b) 'w+' c) 'r+' d) 'a+'

10. Which function is used to open a file in Python?


a) openfile() b) read() c) open() d) [Link]()

11. The default mode for open() function is ________.


a) ‘r’ b) ‘r+’ c) ‘a’ d) ‘w’

12. What is the main advantage of using with open() in Python?


a) It increases file size b) It automatically closes the file
c) It prevents file creation d) It opens multiple files at once

13. Which is the correct syntax for reading a file using with?
a) with open("[Link]", "read"): b) open with("[Link]", "r"):
c) with open("[Link]", "r") as f: d) with file("[Link]"):

14. ______ open("[Link]", "w") as f:


a) file b) read c) with d) text

15. How many parameter(s) are there for open( )?


a) 1 b) 2 c) 3 d) 4

You might also like