wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Basics: Dictionaries and Strings

Total questions: 10

Worksheet time: 6mins

Name
Class
Date
1.

How to define an empty dictionary?

a)

my_dict = {}

b)

my_dict = empty_dict()

c)

my_dict = []

d)

my_dict = ()

2.

How to define a dictionary with one person (name) and its age?

a)

ages = {"Abraham"=1000}

b)

ages = ["Abraham": 1000]

c)

ages = {"Abraham": 1000}

d)

ages = ["Abraham"=1000]

3.

How to access the value matching a key "China" in a dictionary countries?

a)

countries{"China"}

b)

countries["China"]

c)

countries("China")

d)

countries.China

4.

What does the following do:

my_dictionary = {"one":1, "two:2}

my_dictionary["one"] = 111

a)

Replace the value of "one" with 111

b)

Nothing because we already have a value "one"

c)

Store a second value "one" with value 111

d)

Raise an Error

5.

How to check a dictionary my_dict has a certain key my_key?

a)

my_key in my_dict

b)

my_dict.has(my_key)

c)

my_dict has my_key

d)

my_dict in my_key

6.

What does the split method do (e.g. my_string.strip(...))?

a)

Return a string with all spaces removed, even in the middle

b)

Return a string with all spaces at the beginning and end removed

c)

Return a list of strings (my_string being cut into slices)

d)

Modify my_string by removing spaces and return nothing

7.

What does the following do?

"1-2-3-4-5-6".split("-")

a)

Return a list of numbers

[1, 2, 3, 4, 5]

b)

Return a list of strings

["1", "2", "3", "4", "5"]

c)

Return a string

"123456"

d)

Raise an Error

8.

What is the purpose of the triple quotes """...""" ?

a)

It is exactly like double quotes

b)

You can put strings on several lines

c)

You can replace variables by their values

d)

It does not exist

9.

What is the difference between single quotes strings '...' and double quotes strings "..."?

a)

Single quotes can only contain a single character

b)

Single quotes cannot have f-strings

c)

Single quotes allow to put string on several lines

d)

They are the same

10.

What is the value of my_string in the following code?

my_string = "abcde"

my_string[1] = "Z"

a)

"abcde"

b)

"Zbcde"

c)

"aZcde"

d)

An Error has been raised