wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Lists, Tuples, Dictionaries, and Sets Quiz

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

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

a)

list = {}

b)

list = ()

c)

list = []

d)

list = <>

2.

How do you access the first element of a list my_list?

a)

my_list[0]

b)

my_list[1]

c)

my_list(-1)

d)

my_list.first()

3.

What is the output of len([1, 2, 3, 4])?

a)

3

b)

4

c)

5

d)

Error

4.

What is the result of [1, 2, 3] + [4, 5]?

a)

[1, 2, 3, 4, 5]

b)

[5, 7, 8]

c)

Error

d)

None

5.

What does my_list[1:3] do?

a)

Returns 1st and 3rd elements

b)

Returns a list with elements at index 1 and 2

c)

Returns all elements except 1 and 3

d)

Syntax error

6.

Which method is used to add an element to a list?

a)

add()

b)

append()

c)

insert()

d)

push()

7.

What is the output of list("abc")?

a)

"abc"

b)

["abc"]

c)

['a', 'b', 'c']

d)

{'a','b','c'}

8.

What does my_list[-1] return?

a)

First element

b)

Second element

c)

Last element

d)

Error

9.

How do you remove an item from a list by index?

a)

remove()

b)

delete()

c)

pop()

d)

discard()

10.

Which method returns the index of a value in a list?

a)

find()

b)

get()

c)

index()

d)

locate()

11.

What is the output of my_list * 2 if my_list = [1, 2]?

a)

[2, 4]

b)

[1, 2, 1, 2]

c)

Error

d)

[1, 2, 2, 4]

12.

What happens if you try to access a list index that doesn’t exist?

a)

Returns None

b)

Returns 0

c)

Raises IndexError

d)

Returns False

13.

Which method adds an item at a specific index?

a)

add()

b)

insert()

c)

append()

d)

extend()

14.

What does my_list.clear() do?

a)

Deletes the list

b)

Empties the list

c)

Sets all elements to None

d)

Returns a new list

15.

Which of the following methods is used to sort a list in ascending order?

a)

sort()

b)

sorted()

c)

Both a and b

d)

None of the above

16.

Which of the following is a valid tuple?

a)

(1, 2, 3)

b)

[1, 2, 3]

c)

{1, 2, 3}

d)

None

17.

What is the output of type((5,))?

a)

int

b)

list

c)

tuple

d)

dict

18.

Can a tuple contain elements of different data types?

a)

Yes

b)

No

19.

What will my_tuple[0] return if my_tuple = (10, 20, 30)?

a)

10

b)

20

c)

30

d)

0

20.

Are tuples mutable?

a)

Yes

b)

No

21.

What is the result of (1, 2) + (3, 4)?

a)

(4, 6)

b)

[1, 2, 3, 4]

c)

(1, 2, 3, 4)

d)

Error

22.

How do you access the last element in a tuple t?

a)

t[0]

b)

t[-1]

c)

t[len(t)]

d)

t.last()

23.

What will len((1, 2, 3, 4)) return?

a)

3

b)

4

c)

5

d)

1

24.

Which method can you use on a tuple?

a)

append()

b)

extend()

c)

count()

d)

remove()

25.

What is the output of (10, 20, 30).count(20)?

a)

1

b)

0

c)

2

d)

Error

26.

How do you define a dictionary in Python?

a)

d = []

b)

d = {}

c)

d = ()

d)

d = set()

27.

Which of the following is a valid dictionary key?

a)

List

b)

Tuple

c)

Dictionary

d)

Set

28.

How do you access a value in a dictionary d by key "name"?

a)

d(name)

b)

d["name"]

c)

d.name

d)

d.get("name")

29.

What does d.get("key", "default") return if key doesn’t exist?

a)

KeyError

b)

None

c)

"default"

d)

Error

30.

Which method removes all items from a dictionary?

a)

clear()

b)

pop()

c)

delete()

d)

remove()

31.

What does d.keys() return?

a)

List of keys

b)

Dict_keys object

c)

Values

d)

Tuple

32.

What is the output of len({"a":1, "b":2})?

a)

1

b)

2

c)

3

d)

0

33.

Which method removes a key and returns its value?

a)

pop()

b)

remove()

c)

discard()

d)

del

34.

Which method merges two dictionaries?

a)

append()

b)

extend()

c)

update()

d)

merge()

35.

Can a dictionary have duplicate keys?

a)

Yes

b)

No

36.

What will d["missing"] return if the key doesn’t exist?

a)

None

b)

KeyError

c)

False

d)

""

37.

How do you add a new key-value pair?

a)

d.add("key", "value")

b)

d["key"] = "value"

c)

d.put("key", "value")

d)

d.insert("key", "value")

38.

What is the result of list(d.values())?

a)

List of keys

b)

List of values

c)

Dictionary

d)

Tuple

39.

Which method returns a view of key-value pairs?

a)

items()

b)

pairs()

c)

get()

d)

all()

40.

What does dict.fromkeys(['a', 'b'], 0) do?

a)

Creates a set

b)

Creates a dict with 'a' and 'b' keys and 0 as values

c)

Creates a list

d)

Error

41.

What is the syntax for creating an empty set?

a)

s = {}

b)

s = []

c)

s = set()

d)

s = ()

42.

What is the result of set("hello")?

a)

{'h', 'e', 'l', 'l', 'o'}

b)

{'h', 'e', 'l', 'o'}

c)

"hello"

d)

['h', 'e', 'l', 'l', 'o']

43.

Which method adds an element to a set?

a)

append()

b)

add()

c)

insert()

d)

update()

44.

What happens if you add a duplicate element to a set?

a)

Error

b)

It's added

c)

It is ignored

d)

Replaces existing

45.

How do you remove an element safely from a set?

a)

remove()

b)

discard()

c)

pop()

d)

delete()

46.

Which set operation returns common elements?

a)

union()

b)

intersection()

c)

difference()

d)

symmetric_difference()

47.

What does set1.union(set2) do?

a)

Returns only elements in set1

b)

Returns elements in set1 and set2

c)

Returns common elements

d)

Modifies set2

48.

Which method removes a random element?

a)

pop()

b)

remove()

c)

discard()

d)

clear()

49.

What is the result of {1, 2} & {2, 3}?

a)

{1, 3}

b)

{1, 2, 3}

c)

{2}

d)

Error

50.

What does s.clear() do for a set s?

a)

Deletes the set

b)

Empties the set

c)

Sets all elements to None

d)

Returns the set