wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Lists and dictionaries revision

Total questions: 40

Worksheet time: 20mins

Name
Class
Date
1.

What are the different data types in Python?

a)

integer, float, string, list, tuple, dictionary, set, and boolean

b)

cat, dog, bird, fish

c)

red, blue, green, yellow

d)

apple, banana, orange, grape

2.

Explain the difference between mutable and immutable data types in Python.

a)

Mutable data types can only be used once, while immutable data types can be reused

b)

Mutable data types are only used for integers, while immutable data types are used for strings

c)

Mutable data types are always larger in size than immutable data types

d)

Mutable data types can be changed after creation, while immutable data types cannot be changed.

3.

Give examples of numeric data types in Python.

a)

dict, set, tuple

b)

int, float, complex

c)

str, bool, list

d)

char, double, real

4.

What is the use of the 'str' data type in Python?

a)

To store and manipulate text

b)

To create loops and conditions

c)

To store images and videos

d)

To perform mathematical operations

5.

How are lists and tuples different in Python?

a)

Lists can be modified after creation, while tuples cannot be modified after creation.

b)

Lists and tuples are the same in Python

c)

Lists and tuples cannot store different data types in Python

d)

Tuples can be modified after creation, while lists cannot be modified after creation

6.

Explain the concept of type conversion in Python.

a)

Type conversion in Python refers to the process of converting lists into dictionaries.

b)

Type conversion in Python refers to the process of converting text into images.

c)

Type conversion in Python refers to the process of converting one data type into another.

d)

Type conversion in Python refers to the process of converting integers into floats.

7.

What is the purpose of the 'bool' data type in Python?

a)

To perform mathematical operations

b)

To store text values

c)

To represent boolean values

d)

To represent date and time values

8.

Discuss the importance of understanding data types in programming.

a)

It has no importance in programming

b)

It only makes the code more complicated

c)

Data types are not relevant in programming

d)

It helps in efficient memory usage, proper data manipulation, and avoiding errors.

9.

How are dictionaries and sets different in Python?

a)

Dictionaries are key-value pairs while sets are unordered collections of unique elements.

b)

Dictionaries are ordered while sets are unordered

c)

Dictionaries can only store integers while sets can store any data type

d)

Dictionaries can have duplicate elements while sets cannot

10.

What are Relational Operators used for in Python?

a)

B. To compare values

b)

D. To validate whether a value is found within a sequence

c)

C. To assign values to variables

d)

A. To perform arithmetic operations like addition, multiplication, division, etc.

11.

How are comments denoted in Python?

a)

A. Using // at the beginning of a line

b)

B. Enclosing text within /* and */

c)

C. Preceding text with # symbol

d)

D. Using around text

12.

How are strings represented in Python?

a)

A. Using single quotes ('') or double quotes ("")

b)

B. Using square brackets []

c)

C. Using curly braces {}

d)

D. Using parentheses ()

13.

What is the purpose of the 'in' keyword in Python?

a)

A. To check if a value is present in a sequence

b)

B. To perform arithmetic operations

c)

C. To define a new variable

d)

D. To compare two strings

14.

What is the purpose of the 'and' keyword in Python?

a)

A. To check if both conditions are true

b)

B. To perform bitwise AND operation

c)

C. To define a new variable

d)

D. To compare two strings

15.

What is the purpose of the 'not' keyword in Python?

a)

A. To negate a boolean value

b)

B. To perform logical OR operation

c)

C. To assign values to variables

d)

D. To compare the memory locations of two objects

16.

What is the purpose of the 'or' keyword in Python?

a)

A. To check if either of the conditions is true

b)

B. To perform bitwise OR operation

c)

C. To define a new variable

d)

D. To compare two strings

17.

How are dictionaries represented in Python?

a)

A. Using single quotes ('') or double quotes ("")

b)

B. Using square brackets []

c)

C. Using curly braces {}

d)

D. Using parentheses ()

18.

What is the purpose of the 'is' keyword in Python?

a)

A. To check if two variables refer to the same object

b)

B. To perform logical OR operation

c)

C. To assign values to variables

d)

D. To compare the memory locations of two objects

19.

How are tuples represented in Python?

a)

A. Using single quotes ('') or double quotes ("")

b)

B. Using square brackets []

c)

C. Using curly braces {}

d)

D. Using parentheses ()

20.

What is the result of the following expression? x = 5 y = 3 z = x + y a) 8 b) 15 c) 53 d) Error

a)

b) 15

b)

c) 53

c)

d) Error

d)

a) 8

21.

Which operator is used for exponentiation in Python?

a)

**

b)

//

c)

*

d)

^

22.

Which operator is used for floor division in Python?

a)

%

b)

*

c)

/

d)

//

23.

Which one is a valid identifier

a)

_count

b)

1count

c)

break

d)

True

24.

Which one is not a valid operator

a)

**

b)

^^

c)

//

d)

*

25.

Python is a general purpose programming language created by

a)

Dennis M. Ritchie

b)

Guido Van Rossum

c)

James Gosling

d)

Bjarne Stroustrup

26.

__________are special words that are used by Python interpreter to recognize the

structure of program.

a)

Tokens

b)

Identifiers

c)

Keywords

d)

Operators

27.

Examples of String Literals

a)

"ABC1273"

b)

nfjdlsj@@$

c)

12638

d)

'7e920938'

28.

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

a)

len( )

b)

pop( )

c)

del( )

d)

keys( )

e)

values( )

29.

Which of the following will give error?

Suppose dict1={"a":1,"b":2,"c":3}

a)

print(len(dict1))

b)

print(dict1.get("b"))

c)

dict1["a"]=5

d)

None of these.

30.

What would be the output of the following code snippet?


a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}

d_items = a_dict.items()

print(d_items)

a)

('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')

b)

dict_items([('color'), ('fruit'), ('pet')])

c)

[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]

d)

dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])

31.

What would the output of the program be?

thisList = ["square", "circle", "triangle", "octagon"]

if "triangle" in thisList:

print("Yes, 'triangle' is in the list")

else:

print("No triangle here!")

a)

Yes, 'triangle' is in the list

b)

"No triangle here!"

32.

What will be the output when this code is executed?

a)

1

2

3

4

5

b)

2

4

c)

1 3 5

d)

1

3

5

33.

What is the output of this code?

a)

5 4 3 2 1

b)

5

4

3

2

1

c)

1

2

3

4

5

d)

1 2 3 4 5

34.

What will be the output of the following Python code?

>>> a={3,4,5}

>>> a.update([1,2,3])

>>> a

a)

Error, no method called update for set data type

b)

{1, 2, 3, 4, 5}

c)

Error, list can’t be added to set

d)

Error, duplicate item present in list

35.

What will be the output of the following code? python my_dict = {'a': 1, 'b': 2} my_dict['a'] = my_dict['a'] * 2 print(my_dict['a'])

a)

1

b)

2

c)

3

d)

4

36.

What will be the output of the following code? python my_dict = {'a': 1, 'b': 2} my_dict.clear() print(my_dict)

a)

{}

b)

None

c)

{'a': 1, 'b': 2}

d)

KeyError

37.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
38.

In an list, what is the first numbered position in which data can be stored?

a)

Position 0

b)

Position 1

39.
The best type of loop to use on a list is
a)
a FOR loop
b)
a WHILE loop
c)
an IF statement
d)
a print() statement
40.
What is the output when we execute list(“hello”)?
a)
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b)
 [‘hello’] 
c)
[‘llo’]
d)
 [‘olleh’]