WorksheetsPython Basics: Dictionaries and Strings
Total questions: 10
Worksheet time: 6mins
How to define an empty dictionary?
my_dict = {}
my_dict = empty_dict()
my_dict = []
my_dict = ()
How to define a dictionary with one person (name) and its age?
ages = {"Abraham"=1000}
ages = ["Abraham": 1000]
ages = {"Abraham": 1000}
ages = ["Abraham"=1000]
How to access the value matching a key "China" in a dictionary countries?
countries{"China"}
countries["China"]
countries("China")
countries.China
What does the following do:
my_dictionary = {"one":1, "two:2}
my_dictionary["one"] = 111
Replace the value of "one" with 111
Nothing because we already have a value "one"
Store a second value "one" with value 111
Raise an Error
How to check a dictionary my_dict has a certain key my_key?
my_key in my_dict
my_dict.has(my_key)
my_dict has my_key
my_dict in my_key
What does the split method do (e.g. my_string.strip(...))?
Return a string with all spaces removed, even in the middle
Return a string with all spaces at the beginning and end removed
Return a list of strings (my_string being cut into slices)
Modify my_string by removing spaces and return nothing
What does the following do?
"1-2-3-4-5-6".split("-")
Return a list of numbers
[1, 2, 3, 4, 5]
Return a list of strings
["1", "2", "3", "4", "5"]
Return a string
"123456"
Raise an Error
What is the purpose of the triple quotes """...""" ?
It is exactly like double quotes
You can put strings on several lines
You can replace variables by their values
It does not exist
What is the difference between single quotes strings '...' and double quotes strings "..."?
Single quotes can only contain a single character
Single quotes cannot have f-strings
Single quotes allow to put string on several lines
They are the same
What is the value of my_string in the following code?
my_string = "abcde"
my_string[1] = "Z"
"abcde"
"Zbcde"
"aZcde"
An Error has been raised
