LoginSignup
0
1

More than 3 years have passed since last update.

[Python]辞書

Last updated at Posted at 2020-05-20

辞書の作り方
{キー1:値1 , キー2:値2}
リストとカッコ {} が違うことに注意

fruits = {"apple":"りんご" , "banana":"バナナ" , "strawberry":"イチゴ"}

出力
辞書[キー]
出力する時のカッコ [] に注意

fruits = {"apple":"りんご" , "banana":"バナナ" , "strawberry":"イチゴ"}

print("appleは" + fruits["apple"] + "です")

出力結果
appleはりんごです


要素の更新
辞書[キー] = 値

fruits = {"apple":"りんご" , "banana":"バナナ" , "strawberry":"イチゴ"}

fruits["banana"] = "ばなな"

要素の追加
辞書[新しいキー] = 値

fruits = {"apple":"りんご" , "banana":"バナナ" , "strawberry":"イチゴ"}

fruits["kiwi"] = "キウイ"
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1