LoginSignup
0
1

More than 3 years have passed since last update.

dictionary{}の使い方

Last updated at Posted at 2020-02-17

dictionary型とは?

 df={"a":1,"b":2,"c":3}
 この時
 a,b,c→key(キー)
 1,2,3→value(値)
 と言う.

辞書型の要素を取り出す

ta=df["a"]
>>>print(ta)
実行結果
>>>1

 この様に要素(value)を取り出すにはkeyを使う

辞書型のkeyを変更する

df["a"]=4
>>>print(df)
参照結果
>>>{"a":4,"b":2,"c":3}

 要素の取り出し方と同じである

辞書型にkeyとvalueを追加する

df["d"]=4#要素を追加する
>>>print(df)
実行結果
>>>{"a":1,"b":2,"c":3,"d":4}

 

辞書型のkeyとvalueを削除する方法

df.pop("d")
>>>print(df)
実行結果
>>>{"a":1,"b":2,"c":3}

 この様にpop(key)を使うと削除出来る

0
1
2

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