Files In Python: MCQs on Files in Python Language

Files In Python. Multiple Choice Questions on the topic of Files in Python language.

Files In Python

 

What is the use of tell() method in python ??

a) tells you the current position within the file
b) tells you the end position within the file
c) tells you the file is opened or not
d) none of the mentioned

 

To read two characters from a file object infile we use ??

a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()

 

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

 

Which one of the following is not attributes of file ??

a) closed
b) softspace
c) rename
d) mode

 

Files In Python

Which of the following statements are true ??

a) When you open a file for reading, if the file does not exist, an error occurs
b) When you open a file for writing, if the file does not exist, a new file is created
c) When you open a file for writing, if the file exists, the existing file is overwritten with the new file
d) All of the mentioned

 

Which of the following mode will refer to binary data ??

a) r
b) w
c) +
d) b

 

What will be the output ??

str = input(“Enter your input: “);
print “Received input is : “, str

 

a) 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

 

To open a file c:\scores.txt for appending data we use ??

a) outfile = open(“c:\\scores.txt”, “a”)
b) outfile = open(“c:\\scores.txt”, “rw”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)

 

Files In Python

What will be the output of the following ??

import sys
sys.stdout.write(‘ Hello\n’)
sys.stdout.write(‘Python\n’)

a) Compilation Error

b) Runtime Error

c) Hello Python

d) Hello
Python

 

What will be the output of this ??

str = raw_input(“Enter your input: “);
print “Received input is : “, str

a) 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

 

To open a file c:\scores.txt for writing we use ??

a) outfile = open(“c:\scores.txt”, “w”)
b) outfile = open(“c:\\scores.txt”, “w”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)

 

What will be the output of the following Python ??

import sys
print ‘Enter your name: ‘,
name = ‘ ‘
while True:
c = sys.stdin.read(1)
if c == ‘\n’:
break
name = name + c
print ‘Your name is:’, name

 

a) myandroid
b) myandroid, myandroid
c) myId
d) None of the mentioned

 

Files In Python

Which are the two built-in functions to read a line of text from standard input which by default comes from the keyboard ??

a) Raw_input & Input
b) Input & Scan
c) Scan & Scanner
d) Scanner

 

To open a file c:\scores.txt for reading we use ??

a) infile = open(“c:\scores.txt”, “r”)
b) infile = open(“c:\\scores.txt”, “r”)
c) infile = open(file = “c:\scores.txt”, “r”)
d) infile = open(file = “c:\\scores.txt”, “r”)

 

Which is/are the basic I/O connections in file ??

a) Standard Input
b) Standard Output
c) Standard Errors
d) All of the mentioned

More Posts

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!