Font size
WorksheetsDFH Class XII
Total questions: 46
Worksheet time: 23mins
A: Strings can be changed during execution
B. Strings can be enclosed within single, double or even triple quotes
C. Strings are immutable
A,B & C are True
A,B are True but C is False
B, C are True but A is False
A,C are True but B is False
Find the output of the following code:
>>>str1='Save Soil'
>>>str1.isalnum( )
Save Soil
True
False
Identify the string membership operators of Python
in, not in
like, not like
as, not as
between, not between
The title( ) function
assigns title
returns the title of the file
returns string in title case
Predict the output:
>>>str1="Rajathi Raja"
>>>print(str1.count('Raja'))
1
2
Error
Raja
Predict the output:
>>>saint="Thiruvalluvar"
>>>print(saint[5:])
valluvar
Thiruvalluvar
uvalluvar
Thiru
s="welcome"
print( s. center (15,'*'))
***welcome***
****welcome****
****welcome***
undefine function center
What is the output of the following code
dict1 = {"key1":1, "key2":2}
dict2 = {"key2":2, "key1":1}
print(dict1 == dict2)
True
False
Select correct ways to create an empty dictionary
sampleDict = {}
sampleDict = dict()
sampleDict = dict{}
Please select all correct ways to empty the following dictionary
student = {
"name": "Emma",
"class": 9,
"marks": 75
}
del student
del student[0:2]
student.clear()
In Python, Dictionaries are immutable
True
False
________________method removes all items from the particular dictionary.
clear( )
pop( )
del ( )
_______________this method deletes the item from the dictionary
pop( )
del( )
clear( )
________________method will returns number of key-value pairs in the given dictionary.
len( )
pop( )
del( )
keys( )
values( )
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","__")
r
a
w
x
see the program and fill in the blank with correct statement.
(a)
See the following code snippet and fill in the blank with appropriate statement
(a)
Fill in the blank with appropriate statement.
(a)
which function is used to read records from a binary file?
pickle.load(f)
pickle.read()
pickle.open()
pickle.dump(l,f)
write statement to use the required module for working with comma separated values (csv) files.
(a)
Write the appropriate statement in the blank.
(a)
Which statement(s) is/are true to open a binary file "Record.dat" for reading and writing.
file =open("Record.dat","wb")
file =open("Record.dat","rb")
file =open("Record.dat","ab")
file =open("Record.dat","rb+")
In Python, by default this EOL character is the
(\eol)
(\n)
(\el)
(\p)
Is there a delimiter for binary files
Yes
No
What will be the output-
f=open('abc.txt','a')
text="xyz"
f.write(text)
f.close()
Writing into the file without erasing old content
Writing into the file by erasing old content
reading from the file without erasing old content
reading from the file by erasing old content
Which function read single line at a time?
read()
read(n)
readline()
readlines()
Q.2 Which of the following statements are not true regarding the opening modes of a file?
When you open a file for reading, if the file does not exist, an error occurs.
When you open a file for writing, if the file does not exist, an error occurs
When you open a file for writing, if the file does not exist, a new file is created.
When you open a file for writing, if the file exists, the existing file is overwritten with the new file.
Q.3 Which module is used to work with binary files?
CSV module
pickle module
math module
binary module
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)) ?
I ca
I can
I c
I can't write one song that's not about you
Can't drink without thinkin' about
I c
you
Is it too late to tell you that
Everything means nothing if I can't have you?
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]) ?
I can't write one song that's not about you
Can't drink without thinkin' about you
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?
I
What is the best way to read the first line of a file?
.read()
.readline()
.readlines()
.read(all)
Which is the best type of loop to write a file in?
While loop
for loop
repeat loop
Why is it best to open a file with "with" in Python?
It automatically closes the file
Easier to read the code
Better for binary files
Closers to the pseudocode
Which function is used to write multiple lines in text file?
write()
writelines()
writeline()
print()
CSV stands for
Comma Separated Values
Comma Spaced Values
Completely Separated VAlues
Comma Segregated Values
Delimeter for CSV file is
Comma
Tab
Space
Semi-colon
Which character can work as delimiter for CSV files:
Comma only
Tab only
Space only
Any character
We can manage (create/read/update)CSV files using
A text editor
A Python program
A Spreadsheet application
All of the above
File opening modes for CSV files are:
Same as those for text files
same as those for binary files
different from text files and binary files
mix of text files and binary files
Which module in Python is used to process csv file
pickle
random
CSV
csv.reader()
CSV module allows writing multiple records in a CSV file using
writerows()
writerow()
writerec()
writelines
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'
It can be treated as a csv file
It can not be treated as CSV file as it is a text file
It can not be treated as CSV file as it contains mixed data
It can not be treated as CSV file as it contains different number of elements in different lines.
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:
rec will be list in 1 element
rec will be list in 3 element
rec will be a nested list of 1 element
rec will be a nested list of 3 elements
The given code is leaving an unwanted blank line after every row in the file sample.csv
The correct
close the file at the end
use keyword argument newline='' with open function
make data a tuple instead of a list
use '\n' as the last element of each record
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:
list
tuple
str
dict
Making some changes in the data of the existing file or adding more data is called
Editing
Appending
Modification
Alteration
