menu

Python Input and Output


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

'rb'

'wb'

'ab'

'xb'


2. Which function is used to change the working directory in Python?

os.chdir()

os.getcwd()

os.mkdir()

D. os.listdir()


3. Which method is used to write a string to a file in Python?

write()

read()

readline()

D. readlines()


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

read()

readline()

readlines()

D. write()


5. Which symbol is used for the newline character in Python?

\n

\t

\r

\s


6. 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()


7. 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")


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

read()

readline()

readlines()

D. write()


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

os.remove()

os.rename()

os.mkdir()

D. os.rmdir()


10. Which function is used to write to an Excel file in Python?

openpyxl.load_workbook()

openpyxl.read_excel()

openpyxl.write_excel()

D. openpyxl.dump_excel()