Mutable, nebo immutable?
Následující funkce přidá do slovníku mapování mezi řetězcem a jeho verzí malými písmeny. Co očekáváš, že budou hodnoty d a s po zavolání funkce?
def store_lower(_dict, _string):
"""Add a mapping between `_string` and a lowercased version of `_string` to `_dict`
Args:
_dict (dict): The dictionary to update.
_string (str): The string to add.
"""
orig_string = _string
_string = _string.lower()
_dict[orig_string] = _string
d = {}
s = 'Hello'
store_lower(d, s)
Toto cvičení je součástí kurzu
Writing Functions in Python
Interaktivní praktické cvičení
Proměňte teorii v praxi s jedním z našich interaktivních cvičení
Začít cvičení