始める無料で始める

ミュータブルかイミュータブルか?

次の関数は、文字列とその小文字版との対応関係を辞書に追加します。関数を呼び出した後、ds の値はどうなると予想しますか?

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)

この演習はコースの一部です

Python関数の書き方

コースを見る

実践的なインタラクティブ演習

理論を実践に変える、インタラクティブな演習のひとつをお試しください

演習を開始する