menu

Python Input and Output


1. Which method is used to read the entire contents of a file as a string in Python?

read()

readline()

readlines()

D. write()


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

csv.reader()

csv.writer()

csv.open()

D. csv.read()


3. Which of the following is used to write binary data to a file in Python?

'rb'

'wb'

'ab'

'xb'


4. How do you open a file for writing in Python?

file = open("filename.txt", "w")

file = open("filename.txt", "r")

file = open("filename.txt", "a")

D. file = open("filename.txt", "x")


5. Which of the following is used to append binary data to a file in Python?

'rb'

'wb'

'ab'

'xb'


6. Which method is used to read a single line from a file in Python?

read()

readline()

readlines()

D. write()


7. Which function is used to write to a JSON file in Python?

json.write()

json.load()

json.dump()

D. json.read()


8. Which method is used to check if a file exists in Python?

exists()

isfile()

isdir()

D. both A and B


9. Which function is used to read a JSON file in Python?

json.read()

json.load()

json.write()

D. json.dump()


10. Which module is used to work with CSV files in Python?

csv

os

sys

D. io