wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

DFH Class XII

Total questions: 46

Worksheet time: 23mins

Name
Class
Date
1.

A: Strings can be changed during execution

B. Strings can be enclosed within single, double or even triple quotes

C. Strings are immutable

a)

A,B & C are True

b)

A,B are True but C is False

c)

B, C are True but A is False

d)

A,C are True but B is False

2.

Find the output of the following code:

>>>str1='Save Soil'

>>>str1.isalnum( )

a)

Save Soil

b)

True

c)

False

3.

Identify the string membership operators of Python

a)

in, not in

b)

like, not like

c)

as, not as

d)

between, not between

4.

The title( ) function

a)

assigns title

b)

returns the title of the file

c)

returns string in title case

5.

Predict the output:

>>>str1="Rajathi Raja"

>>>print(str1.count('Raja'))

a)

1

b)

2

c)

Error

d)

Raja

6.

Predict the output:

>>>saint="Thiruvalluvar"

>>>print(saint[5:])

a)

valluvar

b)

Thiruvalluvar

c)

uvalluvar

d)

Thiru

7.

s="welcome"

print( s. center (15,'*'))

a)

***welcome***

b)

****welcome****

c)

****welcome***

d)

undefine function center

8.

What is the output of the following code

dict1 = {"key1":1, "key2":2}

dict2 = {"key2":2, "key1":1}

print(dict1 == dict2)

a)

True

b)

False

9.

Select correct ways to create an empty dictionary

a)

sampleDict = {}

b)

sampleDict = dict()

c)

sampleDict = dict{}

10.

Please select all correct ways to empty the following dictionary

student = {

"name": "Emma",

"class": 9,

"marks": 75

}

a)

del student

b)

del student[0:2]

c)

student.clear()

11.

In Python, Dictionaries are immutable

a)

True

b)

False

12.

________________method removes all items from the particular dictionary.

a)

clear( )

b)

pop( )

c)

del ( )

13.

_______________this method deletes the item from the dictionary

a)

pop( )

b)

del( )

c)

clear( )

14.

________________method will returns number of key-value pairs in the given dictionary.

a)

len( )

b)

pop( )

c)

del( )

d)

keys( )

e)

values( )

15.

Mode in the following program to open file for writing in a mode where new data will be added at the end of old data


file =open("poem.txt","__")

a)

r

b)

a

c)

w

d)

x

16.

see the program and fill in the blank with correct statement.

(a)  

17.

See the following code snippet and fill in the blank with appropriate statement

(a)  

18.

Fill in the blank with appropriate statement.

(a)  

19.

which function is used to read records from a binary file?

a)

pickle.load(f)

b)

pickle.read()

c)

pickle.open()

d)

pickle.dump(l,f)

20.

write statement to use the required module for working with comma separated values (csv) files.

(a)  

21.

Write the appropriate statement in the blank.

(a)  

22.

Which statement(s) is/are true to open a binary file "Record.dat" for reading and writing.

a)

file =open("Record.dat","wb")

b)

file =open("Record.dat","rb")

c)

file =open("Record.dat","ab")

d)

file =open("Record.dat","rb+")

23.

In Python, by default this EOL character is the

a)

(\eol)

b)

(\n)

c)

(\el)

d)

(\p)

24.

Is there a delimiter for binary files

a)

Yes

b)

No

25.

What will be the output-

f=open('abc.txt','a')

text="xyz"

f.write(text)

f.close()

a)

Writing into the file without erasing old content

b)

Writing into the file by erasing old content

c)

reading from the file without erasing old content

d)

reading from the file by erasing old content

26.

Which function read single line at a time?

a)

read()

b)

read(n)

c)

readline()

d)

readlines()

27.

Q.2 Which of the following statements are not true regarding the opening modes of a file?

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, an error occurs

c)

When you open a file for writing, if the file does not exist, a new file is created.

d)

When you open a file for writing, if the file exists, the existing file is overwritten with the new file.

28.

Q.3 Which module is used to work with binary files?

a)

CSV module

b)

pickle module

c)

math module

d)

binary module

29.

Q1. Given the following file opened as song_file:


I can't write one song that's not about you

Can't drink without thinkin' about you

Is it too late to tell you that

Everything means nothing if I can't have you?


What is the result of

print(song_file.read(4)) ?

a)

I ca

b)

I can

I c

I can't write one song that's not about you

Can't drink without thinkin' about

c)

I c

d)

you

Is it too late to tell you that

Everything means nothing if I can't have you?

30.

Given the following file opened as song_file:


I can't write one song that's not about you

Can't drink without thinkin' about you

Is it too late to tell you that

Everything means nothing if I can't have you?


What is the result of

print(text_file.readlines()[1]) ?

a)

I can't write one song that's not about you

b)

Can't drink without thinkin' about you

I can't write one song that's not about you

Can't drink without thinkin' about

c)

you

Is it too late to tell you that

Everything means nothing if I can't have you?

d)

I

31.

What is the best way to read the first line of a file?

a)

.read()

b)

.readline()

c)

.readlines()

d)

.read(all)

32.

Which is the best type of loop to write a file in?

a)

While loop

b)

for loop

c)

repeat loop

33.

Why is it best to open a file with "with" in Python?

a)

It automatically closes the file

b)

Easier to read the code

c)

Better for binary files

d)

Closers to the pseudocode

34.

Which function is used to write multiple lines in text file?

a)

write()

b)

writelines()

c)

writeline()

d)

print()

35.

CSV stands for

a)

Comma Separated Values

b)

Comma Spaced Values

c)

Completely Separated VAlues

d)

Comma Segregated Values

36.

Delimeter for CSV file is

a)

Comma

b)

Tab

c)

Space

d)

Semi-colon

37.

Which character can work as delimiter for CSV files:

a)

Comma only

b)

Tab only

c)

Space only

d)

Any character

38.

We can manage (create/read/update)CSV files using

a)

A text editor

b)

A Python program

c)

A Spreadsheet application

d)

All of the above

39.

File opening modes for CSV files are:

a)

Same as those for text files

b)

same as those for binary files

c)

different from text files and binary files

d)

mix of text files and binary files

40.

Which module in Python is used to process csv file

a)

pickle

b)

random

c)

CSV

d)

csv.reader()

41.

CSV module allows writing multiple records in a CSV file using

a)

writerows()

b)

writerow()

c)

writerec()

d)

writelines

42.

The content of a file "sample.txt" are shown below:


1,2,3,4

'a', 'b', 'c'

5, 23, 'me', 'peace'

'to', 'be', 'or' 'not'

a)

It can be treated as a csv file

b)

It can not be treated as CSV file as it is a text file

c)

It can not be treated as CSV file as it contains mixed data

d)

It can not be treated as CSV file as it contains different number of elements in different lines.

43.

The contents of a text file"sample.txt", and a script to read the file contents are shown


Pick the correct statement w.r.t the given contents and code:

a)

rec will be list in 1 element

b)

rec will be list in 3 element

c)

rec will be a nested list of 1 element

d)

rec will be a nested list of 3 elements

44.

The given code is leaving an unwanted blank line after every row in the file sample.csv


The correct

a)

close the file at the end

b)

use keyword argument newline='' with open function

c)

make data a tuple instead of a list

d)

use '\n' as the last element of each record

45.

The contents of a CSV file "sample.csv" and the code to read and display the data in this file are given


What will be the data type of variable rec used in the code:

a)

list

b)

tuple

c)

str

d)

dict

46.

Making some changes in the data of the existing file or adding more data is called

a)

Editing

b)

Appending

c)

Modification

d)

Alteration