menu

Python Input and Output


1. Which function is used to close a file in Python?

close()

exit()

end()

D. finish()


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


3. Which function is used to rename a file in Python?

os.rename()

os.remove()

os.mkdir()

D. os.rmdir()


4. Which function is used to remove a directory in Python?

os.rmdir()

os.remove()

os.rename()

D. os.mkdir()


5. Which of the following modes is used to write to a file in Python?

'r'

'w'

'a'

'x'


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

os.chdir()

os.getcwd()

os.mkdir()

D. os.listdir()


7. How do you open a file for appending in Python?

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

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

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

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


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

write()

writelines()

append()

D. None of the above


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

write()

writelines()

append()

D. None of the above


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

'rb'

'wb'

'ab'

'xb'