python3

python3 で辞書(dictionary)の一部を del で削除する

投稿日:2020年11月27日 更新日:

辞書の一部を削除するには、del で消去したいキーを指定する。

dict1 = {"名前":"太郎", "年齢": 20, "住所": "東京都千代田区大手町1-1"}
print(dict1)
del dict1["名前"]
print(dict1)

結果

{'名前': '太郎', '年齢': 20, '住所': '東京都千代田区大手町1-1'}
{'年齢': 20, '住所': '東京都千代田区大手町1-1'}

-python3
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

matplotlib で折れ線グラフの下部に色をつけて塗りつぶす方法

pyplot の fill_between を使う。 例 from matplotlib import pyplot as plt data_x = [25,26,27] data_y = & …

no image

matplotlib で、縦横の線(グリッド)を描く方法

pyplot grid で縦横線(罫線のようなもの)を引くことができる。 例 from matplotlib import pyplot as plt data_x = [25,26,27] …

no image

gnuplot で、グラフの形を正方形にする方法

set size square または、その省略形で set size sq というコマンドを使えば正方形の中にグラフを描くことができる。 例 set size square plot cos(x) …

no image

matplotlib で、グラフのタイトルに上付き文字を入力する方法

数学記号などで、グラフのタイトルに上付きの文字を入力したい場合がある。 その場合は次のように書いて設定できる。 例 import numpy as np from matplotlib import …

no image

python3 で、dictionary のキー一覧を取得する方法

dict.keys() でキーを取得することができる。 参考:dictionary の値一覧を取得するときは、dict.values() を使う。 例 print(dict.keys())