Strings and dictionaries Flashcards
Each element that is stored in a dictionary has two parts: ___
a list and a value.
a list and an index.
a key and a value.
a list and a class.
a key and a value
A dictionary can include the same value several times but cannot include the same key several times.
TRUE
FALSE
TRUE
You cannot use a for loop to iterate over the characters in a string.
TRUE
FALSE
FALSE
The values that are stored in a single dictionary can be of different types.
TRUE
FALSE
TRUE
The elements in a dictionary are stored in ascending order, by the keys of the key-value pairs.
FALSE
FALSE
What will be assigned to the variable z after the following code executes?
x = '123 Panorama Ave' z = x[4:]
’ Ave’
‘123 ‘
‘Panorama’
‘Panorama Ave’
‘Panorama Ave’
To test if the user input contains only alphabetical letters, you can use the ________ string method.
isalpha()
ascii()
strip()
isletter()
isalpha()
The ________ method returns all the dictionary key-value pairs in the form of a sequence of tuples.
items()
values()
tuples()
sequence()
items()
If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError exception is raised.
TRUE
FALSE
TRUE
Dictionaries are immutable objects.
TRUE
FALSE
FALSE
In slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead.
TRUE
FALSE
TRUE
The following expression is valid: string[0] = ‘k’
TRUE
FALSE
FALSE
If a whole paragraph is included in a single string, the split() method can be used to obtain a list of the sentences in the paragraph.
TRUE
FALSE
TRUE
A dictionary can include the same value several times but cannot include the same key several times.
TRUE
FALSE
TRUE
If you try to retrieve a value from a dictionary using a nonexistent key, an IndexError exception is raised.
TRUE
FALSE
FALSE