Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

QUIZ 22

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which of the following command is used to open a file “c:\temp.txt” in read-mode only?

a)

infile = open(“c:\temp.txt”, “r”)

b)

infile = open(“c:\\temp.txt”, “r”)

c)

infile = open(file = “c:\temp.txt”, “r+”)

d)

infile = open(file = “c:\\temp.txt”, “r+”)

2.

Which of the following command is used to open a file “c:\temp.txt” in write-mode only?

a)

outfile = open(“c:\temp.txt”, “w”)

b)

outfile = open(“c:\\temp.txt”, “w”)

c)

outfile = open(file = “c:\temp.txt”, “w+”)

d)

outfile = open(file = “c:\\temp.txt”, “w+”)

3.

Which of the following command is used to open a file “c:\temp.txt” in append-mode?

a)

outfile = open(“c:/temp.txt”, “a”)

b)

outfile = open(“c:\\temp.txt”, “rw”)

c)

outfile = open(“c:\temp.txt”, “w+”)

d)

outfile = open(“c:\\temp.txt”, “r+”)

e)

outfile = open(“c:\\temp.txt”, “a”)

4.

Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?

a)

file.read(n)

b)

n = file.read()

c)

file.readline(n)

d)

file.readlines()

5.

Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?

a)

tmpfile.read(n)

b)

tmpfile.read()

c)

tmpfile.readline()

d)

tmpfile.readlines()

6.

Which of the following commands can be used to read the next line in a file using the file object <tmpfile>?

a)

tmpfile.read(n)

b)

tmpfile.read()

c)

tmpfile.readline()

d)

tmpfile.readlines()

7.

Which of the following commands can be used to read the remaining lines in a file using the file object <tmpfile>?

a)

tmpfile.read(n)

b)

tmpfile.read()

c)

tmpfile.readline()

d)

tmpfile.readlines()

8.

What does the <readlines()> method returns?

a)

str

b)

a list of lines

c)

list of single characters

d)

list of integers

9.

Which of the following command is used to open a file “c:\temp.txt” for writing in binary format only?

a)

outfile = open(“c:\temp.txt”, “w”)

b)

outfile = open(“c:\\temp.txt”, “wb”)

c)

outfile = open(“c:\temp.txt”, “w+”)

d)

outfile = open(“c:\\temp.txt”, “wb+”)

10.

Which of the following command is used to open a file “c:\temp.txt” for reading in binary format only?

a)

outfile = open(“c:\temp.txt”, “r”)

b)

outfile = open(“c:\\temp.txt”, “rb”)

c)

outfile = open(“c:\temp.txt”, “r+”)

d)

outfile = open(“c:\\temp.txt”, “rb+”)