menu

Python Input and Output


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

write()

writelines()

append()

D. None of the above


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

os.remove()

os.rename()

os.mkdir()

D. os.rmdir()


3. Which of the following is used to read a binary 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 create a new sheet in an Excel file using openpyxl?

workbook.create_sheet()

workbook.new_sheet()

workbook.add_sheet()

D. workbook.append_sheet()


6. Which of the following is used to read binary data from a file in Python?

read()

readline()

readlines()

D. None of the above


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

write()

read()

close()

D. open()


8. Which of the following is used to close a file in Python?

close()

write()

read()

D. open()


9. Which of the following modes is used to append data to a file in Python?

'r'

'w'

'a'

'x'


10. Which method is used to read all the lines of a file into a list in Python?

read()

readline()

readlines()

D. write()