Mutable 或 immutable?
以下函式會在字典中新增一個對應,將某個字串與其小寫版本配對。呼叫函式之後,你預期 d 與 s 的值會是什麼?
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)
本練習屬於課程
