Python Input and Output
Python Input and Output - Important Points
6. | Which function is used to close a file in Python? |
---|
A. close()
B. exit()
C. end()
D. D. finish()
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The close() function is used to close a file in Python.
7. | Which method is used to read the entire contents of a file as a string in Python? |
---|
A. read()
B. readline()
C. readlines()
D. D. write()
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The read() method is used to read the entire contents of a file as a string in Python.
8. | Which method is used to read a single line from a file in Python? |
---|
A. read()
B. readline()
C. readlines()
D. D. write()
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The readline() method is used to read a single line from a file in Python.
9. | Which method is used to read all the lines of a file into a list in Python? |
---|
A. read()
B. readline()
C. readlines()
D. D. write()
View Answer Discuss Work SpaceAnswer: option c
Explanation:
The readlines() method is used to read all the lines of a file into a list in Python.
10. | Which method is used to write a string to a file in Python? |
---|
A. write()
B. read()
C. readline()
D. D. readlines()
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The write() method is used to write a string to a file in Python.