Q: In file handling, what does this terms means “r, a”?
Solution: r- reading, a-appending.
Q: What is the use of “w” in file handling?
Solution: This opens the file for writing. It will create the file if it doesn’t exist, and if it does, it will overwrite it. fh = open(“filename_here”, “w”).
Q: What is the use of “a” in file handling?
Solution: This opens the fhe file in appending mode. That means, it will be open for writing and everything will be written to the end of the file. fh =open(“filename_here”, “a”).
Q: Which function is used to read all the characters?
Solution: The read function reads all characters fh = open(“filename”, “r”) content = fh.read().
Q: Which function is used to read single line from file?
Solution: The readline function reads a single line from the file fh = open(“filename”, “r”) content = fh.readline().
Q: Which function is used to write all the characters?
Solution: To write a fixed sequence of characters to a file fh = open(“hello.txt”,”w”) write(“Hello World”).
Q: Which function is used to write a list of string in a file?
Solution: With the writeline function you can write a list of strings to a file fh = open(“hello.txt”, “w”) lines_of_text = [“a line of text”, “another line of text”, “a third line”] fh.writelines(lines_of_text).
Q: Which function is used to close a file in python?
Solution: f.close()to close it and free up any system resources taken up by the open file.
Q: Is it possible to create a text file in python?
Solution: Yes we can create a file in python. Creation of file is as shown below. file = open(“newfile.txt”, “w”) file.write(“hello world in the new file ”) file.write(“and another line ”) file.close().
Q: Which of the following are the modes of both writing and reading in binary format in file?
Solution: Here is the description below “w” Opens a file for writing only. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing. “wb” Opens a file for writing only in binary format. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing. “w+” Opens a file for both writing and reading. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing. “wb+” Opens a file for both writing and reading in binary format. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing.
You Have Score    | /10 |