What does the w mode indicate when opening a file in Python?
A. Write mode
B. With mode
C. Wrong mode
D. Wide mode
Select an option to see the answer and solution.
Which of the following is not a valid mode to open a file?
Select an option to see the answer and solution.
How can you copy the contents of one file to another in Python?
A. By reading from one file and writing to another
B. By using the copy() method
C. By using the duplicate() method
D. By using the transfer() method
Select an option to see the answer and solution.
Which one of the following is not attributes of file?
A. closed
B. softspace
C. rename
D. mode
Select an option to see the answer and solution.
What is the use of "w" in file handling?
A. Read
B. Write
C. Append
D. None of the mentioned
Select an option to see the answer and solution.
What will be the output of the following Python code?
str = raw_input("Enter your input: ");
print "Received input is : ", strA. Enter your input: Hello Python
Received input is : Hello Python
B. Enter your input: Hello Python
Received input is : Hello
C. Enter your input: Hello Python
Received input is : Python
D. None of the mentioned
Select an option to see the answer and solution.
What will be the output of the following Python code?
fo = open("foo.txt", "rw+")
print "Name of the file: ", fo.name
# Assuming file has following 5 lines
# This is 1st line
# This is 2nd line
# This is 3rd line
# This is 4th line
# This is 5th line
for index in range(5):
line = fo.next()
print "Line No %d - %s" % (index, line)
# Close opened file
fo.close()A. Compilation Error
B. Syntax Error
C. Displays Output
D. None of the mentioned
Select an option to see the answer and solution.
What will be the output of the following Python code?
f = None
for i in range (5):
with open("data.txt", "w") as f:
if i > 2:
break
print(f.closed)A. True
B. False
C. None
D. Error
Select an option to see the answer and solution.
How do you rename a file?
A. fp.name = 'new_name.txt'
B. os.rename(existing_name, new_name)
C. os.rename(fp, new_name)
D. os.set_name(existing_name, new_name)
Select an option to see the answer and solution.
How can you read the entire contents of a binary file in Python?
A. By using the read() method on a file object
B. By using the readlines() method on a file object
C. By using the readall() method on a file object
D. By using the readbinary() method
Select an option to see the answer and solution.
What will be the output of the following Python code?
str = input("Enter your input: ");
print "Received input is : ", strA. Enter your input: [x*5 for x in range(2,10,2)]
Received input is : [x*5 for x in range(2,10,2)]
B. Enter your input: [x*5 for x in range(2,10,2)]
Received input is : [10, 30, 20, 40]
C. Enter your input: [x*5 for x in range(2,10,2)]
Received input is : [10, 10, 30, 40]
D. None of the mentioned
Select an option to see the answer and solution.
What is unpickling?
A. It is used for object serialization
B. It is used for object deserialization
C. None of the mentioned
D. All of the mentioned
Select an option to see the answer and solution.
The readlines() method returns . . . . . . . .
A. str
B. a list of lines
C. a list of single characters
D. a list of integers
Select an option to see the answer and solution.
What is the output of the following code:with open('data.txt', 'r') as file: lines = file.readlines() print(len(lines))
A. The number of lines in data.txt
B. An error will occur
C. The content of data.txt
D. The file object file
Select an option to see the answer and solution.
To read the next line of the file from a file object infile, we use . . . . . . . .
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Select an option to see the answer and solution.
How can you rename a file in Python?
A. By using the os.rename() function
B. By using the file.rename() method
C. By using the file.rename_to() method
D. By using the rename() method
Select an option to see the answer and solution.
What is the pickling?
A. It is used for object serialization
B. It is used for object deserialization
C. None of the mentioned
D. All of the mentioned
Select an option to see the answer and solution.
What is the output of the following code:with open('data.txt', 'r') as file: content = file.read(10) print(content)
A. The first 10 characters of data.txt
B. An error will occur
C. The content of data.txt
D. The file object file
Select an option to see the answer and solution.
How do you close a file object (fp)?
A. close(fp)
B. fclose(fp)
C. fp.close()
D. fp.__close__()
Select an option to see the answer and solution.
What is the use of seek() method in files?
A. sets the file's current position at the offset
B. sets the file's previous position at the offset
C. sets the file's current position within the file
D. none of the mentioned
Select an option to see the answer and solution.