wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python_string_set_dict

Total questions: 60

Worksheet time: 30mins

Name
Class
Date
1.
What is the output of 'Python'.upper()?
a)
PYthon
b)
python
c)
PYTHON
d)
Python
2.
What does len('hello world') return?
a)
10
b)
12
c)
11
d)
None
3.
Which method removes whitespace from both ends of a string?
a)
cut()
b)
strip()
c)
trim()
d)
remove()
4.
Which operator is used to concatenate two strings in Python?
a)
*
b)
&
c)
+
d)
concat()
5.
What will be the output of 'abc' * 3?
a)
abc3
b)
abcabcabc
c)
3abc
d)
Error
6.
What does 'in' keyword check for in strings?
a)
Length
b)
Membership
c)
Equality
d)
Index
7.
What is the default separator in split()?
a)
Whitespace
b)
None
c)
,
d)
;
8.
What will 'Hello'.find('l') return?
a)
3
b)
2
c)
1
d)
0
9.
Which method converts '123' into integer?
a)
str(123)
b)
float('123')
c)
int('123')
d)
toInt('123')
10.
What will 'Python'.replace('P','J') return?
a)
PythonP
b)
Jython
c)
Error
d)
JythonJ
11.
What is slicing 'Python'[1:4]?
a)
Pyt
b)
yth
c)
tho
d)
ytho
12.
What is output of 'Python'[::-1]?
a)
nohtyP
b)
error
c)
Python
d)
tyP
13.
What is output of 'abc'.isalpha()?
a)
None
b)
Error
c)
False
d)
True
14.
What does ord('A') return?
a)
65
b)
64
c)
66
d)
97
15.
What is output of chr(66)?
a)
A
b)
B
c)
C
d)
b
16.
Which method checks if a string starts with given prefix?
a)
begins()
b)
prefix()
c)
start()
d)
startswith()
17.
What is output of 'HELLO'.lower()?
a)
hello
b)
Hello
c)
error
d)
HELLO
18.
What is output of 'hello'.capitalize()?
a)
HELLO
b)
Error
c)
hello
d)
Hello
19.
Which escape character represents newline?
a)
\b
b)
\r
c)
\n
d)
\t
20.
Which function converts any data type to a string?
a)
string()
b)
eval()
c)
str()
d)
repr()
21.
What is the output of len({1,2,2,3})?
a)
4
b)
Error
c)
3
d)
2
22.
Which function adds an element to a set?
a)
extend()
b)
append()
c)
insert()
d)
add()
23.
Which function removes an element from a set?
a)
delete()
b)
pop()
c)
remove()
d)
discard()
24.
Sets are ________
a)
indexed
b)
unordered
c)
ordered
d)
immutable
25.
Can a set contain duplicate elements?
a)
No
b)
Only strings
c)
Sometimes
d)
Yes
26.
Which method removes all elements from a set?
a)
remove()
b)
pop()
c)
clear()
d)
delete()
27.
What is output of {1,2} | {2,3}?
a)
{1,2,3}
b)
{1,2}
c)
{1,3}
d)
{2,3}
28.
What is output of {1,2,3} & {2,3,4}?
a)
{2,3}
b)
{1,2}
c)
{1,3,4}
d)
{3,4}
29.
What is output of {1,2,3} - {2,3,4}?
a)
{1,2}
b)
{1}
c)
{2,3}
d)
{4}
30.
Which method returns union of two sets?
a)
union()
b)
join()
c)
combine()
d)
merge()
31.
What is type of set()?
a)
<class 'set'>
b)
<class 'dict'>
c)
<class 'tuple'>
d)
<class 'list'>
32.
What happens if we add a list to a set?
a)
TypeError
b)
Added
c)
Ignored
d)
Converted
33.
Which method returns intersection?
a)
common()
b)
intersection()
c)
and()
d)
same()
34.
Which method returns difference?
a)
subtract()
b)
diff()
c)
minus()
d)
difference()
35.
Which method checks disjoint sets?
a)
disjoint()
b)
notcommon()
c)
isdisjoint()
d)
separate()
36.
Which method copies a set?
a)
duplicate()
b)
replicate()
c)
copy()
d)
clone()
37.
What is output of set('aaabb')?
a)
{'a','a','b'}
b)
{'aa','bb'}
c)
{'b'}
d)
{'a', 'b'}
38.
Which keyword checks membership?
a)
contains
b)
has
c)
in
d)
exists
39.
Can a set contain mutable elements?
a)
No
b)
Only dicts
c)
Only lists
d)
Yes
40.
What is frozen set?
a)
Immutable set
b)
Ordered set
c)
Mutable set
d)
Empty set
41.
How do you access a value by key?
a)
dict[key]
b)
dict.getvalue()
c)
dict.value(key)
d)
dict.key[]
42.
What is output of len({'a':1,'b':2})?
a)
2
b)
1
c)
Error
d)
3
43.
Which method returns all keys?
a)
keys()
b)
values()
c)
items()
d)
getkeys()
44.
Which method returns all values?
a)
keys()
b)
values()
c)
get()
d)
items()
45.
Which method returns key-value pairs?
a)
pairs()
b)
both()
c)
together()
d)
items()
46.
Which method removes all items?
a)
discard()
b)
delete()
c)
clear()
d)
remove()
47.
Can a dictionary have duplicate keys?
a)
No
b)
Sometimes
c)
Yes
d)
Only integers
48.
Which method removes a specific key?
a)
discard()
b)
pop()
c)
remove()
d)
delete()
49.
Which method returns value for a given key?
a)
find()
b)
read()
c)
fetch()
d)
get()
50.
Which operator is used to add new key-value pair?
a)
+
b)
append()
c)
assignment (=)
d)
*
51.
What is output of list({'x':1,'y':2})?
a)
[(1,2)]
b)
['x','y']
c)
['x:1','y:2']
d)
['x']
52.
What is default value of get() if key not found?
a)
0
b)
None
c)
Error
d)
False
53.
Can dictionary keys be lists?
a)
Yes
b)
No
c)
Sometimes
d)
Only empty lists
54.
Can dictionary keys be tuples?
a)
No
b)
Sometimes
c)
Yes
d)
Only integers
55.
Which method adds multiple pairs?
a)
update()
b)
merge()
c)
extend()
d)
combine()
56.
Which keyword checks key existence?
a)
in
b)
keyof
c)
exists
d)
has
57.
What is output of {'a':1}.get('b',0)?
a)
0
b)
1
c)
Error
d)
None
58.
Which function returns number of key-value pairs?
a)
length()
b)
size()
c)
len()
d)
count()
59.
What is output of dict(a=1,b=2)?
a)
{'a','b'}
b)
{'a=1','b=2'}
c)
{'a':1,'b':2}
d)
{1,2}
60.
Dictionaries are ________
a)
indexed
b)
unordered
c)
immutable
d)
ordered