wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz: Lists, Tuples, and Strings

Total questions: 56

Worksheet time: 28mins

Name
Class
Date
1.

What is the correct way to create a list in Python?

a)

list = [1, 2, 3]

b)

list = (1, 2, 3)

c)

list = {1, 2, 3}

d)

list = <1,2,3>

2.

Which method adds an element at the end of a list?

a)

append()

b)

add()

c)

insert()

d)

extend()

3.

Which of the following reverses a list in place?

a)

list.reverse()

b)

reversed(list)

c)

list[::-1]

d)

list.flip()

4.

Which of these statements is true about tuples?

a)

Tuples are immutable

b)

Tuples are mutable

c)

Tuples can be changed

d)

Tuples cannot be indexed

5.

Strings in Python are _______.

a)

Immutable

b)

Mutable

c)

Dynamic

d)

Unhashable

6.
What is the correct way to create a list in Python?
a)
list = [1, 2, 3]
b)
list = (1, 2, 3)
c)
list = {1, 2, 3}
d)
list = <1,2,3>
7.
What will be the output of: print([1,2,3] + [4,5])
a)
[1,2,3,4,5]
b)
[1,2,3][4,5]
c)
Error
d)
[[1,2,3],[4,5]]
8.
Which method adds an element at the end of a list?
a)
append()
b)
add()
c)
insert()
d)
extend()
9.
What is the output of: a=[1,2,3]; a.insert(1,10); print(a)
a)
[1,10,2,3]
b)
[10,1,2,3]
c)
[1,2,10,3]
d)
Error
10.
Which method removes the first matching element from a list?
a)
remove()
b)
pop()
c)
discard()
d)
delete()
11.
What is the output of: a=[1,2,3]; a.pop(); print(a)
a)
[1,2]
b)
[1,3]
c)
[2,3]
d)
Error
12.
Which of the following creates a shallow copy of a list?
a)
b = a[:]
b)
b = copy.deepcopy(a)
c)
b = list(a)
d)
Both 1 and 3
13.
What is the result of len([1,[2,3],4])?
a)
3
b)
4
c)
5
d)
2
14.
Which statement is true about Python lists?
a)
Lists are mutable
b)
Lists are immutable
c)
Lists cannot contain duplicates
d)
Lists are faster than tuples
15.
What is the result of: [1,2]*2
a)
[1,2,1,2]
b)
[2,2,1,1]
c)
[[1,2],[1,2]]
d)
Error
16.
Which of the following reverses a list in place?
a)
list.reverse()
b)
reversed(list)
c)
list[::-1]
d)
list.flip()
17.
What is the output: a=[1,2,3]; print(a[::-1])
a)
[3,2,1]
b)
[1,2,3]
c)
[2,3,1]
d)
Error
18.
How can we remove all items from a list?
a)
list.clear()
b)
del list
c)
list.removeAll()
d)
list = []
19.
Which of these creates a list comprehension that squares numbers 0–4?
a)
[x**2 for x in range(5)]
b)
[x^2 for x in range(5)]
c)
(x**2 for x in range(5))
d)
{x**2 for x in range(5)}
20.
What is printed: a=[1,2,3]; b=a; b.append(4); print(a)
a)
[1,2,3,4]
b)
[1,2,3]
c)
Error
d)
[4]
21.
What is the result of sum([i for i in range(4)])?
a)
6
b)
10
c)
4
d)
3
22.
Which list method combines two lists?
a)
extend()
b)
append()
c)
concat()
d)
add()
23.
How to check if 5 exists in list a?
a)
5 in a
b)
a.has(5)
c)
exist(a,5)
d)
find(a,5)
24.
What does list comprehension [x for x in range(5) if x%2==0] return?
a)
[0,2,4]
b)
[1,3]
c)
[2,4]
d)
[0,1,2,3,4]
25.
What will print: a=[1,2,3]; a[1:]=[10,20]; print(a)
a)
[1,10,20]
b)
[10,20,3]
c)
[1,2,3]
d)
Error
26.
What is the correct way to create a tuple?
a)
t=(1,2,3)
b)
t=[1,2,3]
c)
t={1,2,3}
d)
t=<1,2,3>
27.
Which of these statements is true about tuples?
a)
Tuples are immutable
b)
Tuples are mutable
c)
Tuples can be changed
d)
Tuples cannot be indexed
28.
What is the output of: t=(1,2,3); print(t[1])
a)
2
b)
1
c)
3
d)
Error
29.
Which function converts a tuple to a list?
a)
list()
b)
tuple()
c)
convert()
d)
tolist()
30.
What is the result: t=(1,2,3)*2
a)
(1,2,3,1,2,3)
b)
[1,2,3,1,2,3]
c)
{1,2,3}
d)
Error
31.
Which operator joins two tuples?
a)
+
b)
*
c)
&
d)
concat()
32.
Can tuples contain mutable objects?
a)
Yes
b)
No
c)
Only integers
d)
Only strings
33.
What is printed: t=(1,2,[3,4]); t[2][0]=5; print(t)
a)
(1,2,[5,4])
b)
(1,2,[3,4])
c)
Error
d)
(1,2,5,4)
34.
How to create a single-element tuple correctly?
a)
t=(1,)
b)
t=(1)
c)
t=[1]
d)
t={1}
35.
Which method returns the number of occurrences of an element in a tuple?
a)
count()
b)
index()
c)
find()
d)
num()
36.
What is the output: t=(10,20,30); print(t.index(20))
a)
1
b)
2
c)
20
d)
Error
37.
Can tuples be nested?
a)
Yes
b)
No
c)
Only 1 level
d)
Only with lists
38.
What is the result: tuple('abc')
a)
('a','b','c')
b)
['a','b','c']
c)
('abc')
d)
Error
39.
Which keyword is used to unpack tuple values?
a)
No keyword needed
b)
unpack
c)
tuple
d)
expand
40.
What is printed: a,b=(1,2); print(a+b)
a)
3
b)
12
c)
(1,2)
d)
Error
41.
What is the correct way to define a string?
a)
s='hello'
b)
s=hello
c)
s={hello}
d)
s=(hello)
42.
Strings in Python are _______.
a)
Immutable
b)
Mutable
c)
Dynamic
d)
Unhashable
43.
What will print: s='abc'; print(s[1])
a)
b
b)
a
c)
c
d)
Error
44.
What is the output: 'Python'.lower()
a)
'python'
b)
'PYTHON'
c)
'Python'
d)
Error
45.
Which method returns the length of a string?
a)
len()
b)
length()
c)
count()
d)
size()
46.
What is the output: 'abc' + '123'
a)
'abc123'
b)
'abc 123'
c)
'abc,123'
d)
Error
47.
What will print: 'hi'*3
a)
'hihihi'
b)
'hi3'
c)
Error
d)
'hi hi hi'
48.
Which method checks if all characters are digits?
a)
isdigit()
b)
isnumber()
c)
isnum()
d)
isalnum()
49.
How to convert a string to uppercase?
a)
str.upper()
b)
string.up()
c)
upper(str)
d)
str.capitalize()
50.
What is the output of: s='python'; print(s[::-1])
a)
'nohtyp'
b)
'python'
c)
Error
d)
'pytnoh'
51.
Which function converts string to list of chars?
a)
list()
b)
split()
c)
chars()
d)
toList()
52.
What is printed: 'a,b,c'.split(',')
a)
['a','b','c']
b)
('a','b','c')
c)
['a,b,c']
d)
Error
53.
Which method removes whitespace from both ends of a string?
a)
strip()
b)
trim()
c)
remove()
d)
clean()
54.
What is the output: 'abc'.replace('b','B')
a)
'aBc'
b)
'abcB'
c)
'aBB'
d)
'ABc'
55.
What is the result: 'HELLO'.lower().capitalize()
a)
'Hello'
b)
'hello'
c)
'HELLO'
d)
'Hello!'
56.
What is printed: s='Data'; print(s*2)
a)
'DataData'
b)
'Data Data'
c)
Error
d)
'2Data'