JavaScript isn't enabled in your browser, so this file can't be opened. Enable and reload.
Python Files
Test your Python skills with w3resource' quiz. This page contains interesting quizzes related to Python File. The test contains 44 questions with no time limit. You will have to read all the given questions, answers and click over the correct answer.
Sign in to Google
to save your progress.
Learn more
* Indicates required question
Which function is used to write all the characters?
*
1 point
write()
writecharacters()
writeall()
writechar()
How do you rename a file?
*
1 point
f.name
= ‘new_name.txt’
os.rename(old_file, new_name)
os.set_name(old_file, new_name)
To read the next line of the file from a file object f, we use ___________
*
1 point
f.read(2)
f.read()
f.readline()
f.readlines()
Which function is used to close a file in Python?
*
1 point
close()
stop()
end()
closefile()
Which of the following statements are true?
*
1 point
When you open a file for reading an error occurs, if the file does not exist
When you open a file for writing a new file is created, if the file does not exist
When you open a file for writing, the existing file is overwritten with the new file, if the file exists,
All of the mentioned
What is the difference between r+ and w+ modes?
*
1 point
No difference
In case of r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+
In case of w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+
Depends on the operating system
To read the entire remaining contents of the file as a string from a file object f, we use ___________
*
1 point
f.read(2)
f.read()
f.readline()
f.readlines()
To read the remaining lines of the file from a file object f, we use __________
*
1 point
f.read(2)
f.read()
f.readline()
f.readlines()
Which function is used to write a list of string in a file?
*
1 point
writeline()
writelines()
writestatement()
writefullline()
Which one of the following is not attributes of file?
*
1 point
closed
softspace
rename
mode
Change the file position to an offset value from the starting position.
*
1 point
fp.seek(offset, 0)
fp.seek(offset, 1)
fp.seek(offset, 2)
none of the mentioned
How do you get the name of a file from a file object (f)?
*
1 point
f.name
f.file(name)
self.__name__(f)
f.__name__()
To open a file c:\text.txt for writing, we use ____________
*
1 point
outfile = open(“c:\test.txt”, “w”)
outfile = open(“c:\\test.txt”, “w”)
outfile = open(file = “c:\test.txt”, “w”)
outfile = open(file = “c:\\test.txt”, “w”)
Is it possible to create a text file in Python?
*
1 point
Yes
No
Machine dependent
All of the mentioned
Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard?
*
1 point
raw_input & Input
Input & Scan
Scan & Scanner
Scanner
To open a file c:\text.txt for appending data, we use ___________
*
1 point
outfile = open(“c:\\test.txt”, “a”)
outfile = open(“c:\\test.txt”, “rw”)
outfile = open(file = “c:\test.txt”, “w”)
outfile = open(file = “c:\\test.txt”, “w”)
In file handling, what does this terms means “r, a”?
*
1 point
read, append
append, read
write, append
none of the mentioned
Which of the following is not a valid attribute of a file object (f)?
*
1 point
f.name
f.closed
f.mode
f.size
Which function is used to read single line from file?
*
1 point
readline()
readlines()
readstatement()
readfullline()
What is the correct syntax of rename() a file?
*
1 point
rename(current_file_name, new_file_name)
rename(new_file_name, current_file_name,)
rename(()(current_file_name, new_file_name))
none of the mentioned
Correct syntax of file.writelines() is?
*
1 point
file.writelines(sequence)
fileObject.writelines()
fileObject.writelines(sequence)
none of the mentioned
Which of the following are the modes of both writing and reading in binary format in file?
*
1 point
wb+
w
wb
w+
What is the use of truncate() method in file?
*
1 point
truncates the file size
deletes the content of the file
deletes the file size
none of the mentioned
What is the use of “a” in file handling?
*
1 point
Read
Write
Append
None of the mentioned
What will be the output of the following Python code?
*
1 point
w3resource
w3resource , w3resource
w3r
None of the mentioned
What will be the output of the following Python code?
*
1 point
Compilation Error
Runtime Error
No Output
Flushes the file when closing them
How do you get the current position within the file?
*
1 point
f.seek()
f.tell()
f.loc
f.pos
What will be the output of the following Python code?
*
1 point
Compilation Error
Runtime Error
output
Output
What is the correct syntax of open() function?
*
1 point
file = open(file_name [, access_mode][, buffering])
file object = open(file_name [, access_mode][, buffering])
file object = open(file_name)
none of the mentioned
What is the correct syntax to remove() a file?
*
1 point
remove(file_name)
remove(new_file_name, current_file_name,)
remove(() , file_name))
none of the mentioned
What happens if no arguments are passed to the seek function?
*
1 point
file position is set to the start of file
file position is set to the end of file
file position remains unchanged
error
Correct syntax of file.readlines() is?
*
1 point
fileObject.readlines( sizehint );
fileObject.readlines();
fileObject.readlines(sequence)
none of the mentioned
Which function is used to read all the characters?
*
1 point
read()
readcharacters()
readall()
readchar()
What is the use of tell() method in python?
*
1 point
Inform you the current position within the file
Inform you the end position within the file
Inform you the file is opened or not
None of the mentioned
Which of the following is not a valid mode to open a file?
*
1 point
ab
rw
r+
w+
To open a file c:\text.txt for reading, we use _____________
*
1 point
f = open(“c:\test.txt”, “r”)
f = open(“c:\\test.txt”, “r”)
f = open(file = “c:\test.txt”, “r”)
f = open(file = “c:\\test.txt”, “r”)
How do you close a file object (fp)?
*
1 point
close(fp)
fclose(fp)
fp.close()
fp.__close__()
What is the use of seek() method in files?
*
1 point
sets the file’s current position at the offset
sets the file’s previous position at the offset
sets the file’s current position within the file
none of the mentioned
What will be the output of the following Python code?
*
1 point
True
False
None
Error
What is the use of “w” in file handling?
*
1 point
Read
Write
Append
None of the mentioned
Which of the following mode will refer to binary data?
*
1 point
r
w
+
b
The readlines() method returns ____________
*
1 point
str
a list of lines
a list of single characters
a list of integers
To read two characters from a file object f, we use ____________
*
1 point
f.read(2)
f.read()
f.readline()
f.readlines()
Command to delete a file.
*
1 point
del(fp)
fp.delete()
os.remove(‘file’)
os.delete(‘file’)
Submit
Clear form
This content is neither created nor endorsed by Google. -
Terms of Service
-
Privacy Policy
Does this form look suspicious?
Report
Forms
Help and feedback
Contact form owner
Help Forms improve
Report