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 で、グラフの点の見た目を変更する方法

「marker」で指定すればよい。 次のページを参考に、plotの「marker」を変更する。 https://matplotlib.org/stable/api/markers_api.html 例 …

no image

pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。

next() を使う。 例 my_arr = [‘春’,’夏’,’秋’,’冬’] my_iter = iter(my_arr) print(next(my_iter,’なし’)) print(next …

no image

matplotlib で、凡例を表示する位置を変更する方法

凡例(legend)の表示位置を変更するには、axis の legend の loc を設定する。 次のリンクhttps://matplotlib.org/stable/api/_as_gen/mat …

no image

matplotlib でグラフの中に注釈の文字を書く方法

annotate を使う。 例 import numpy as np from matplotlib import pyplot as plt x = np.linspace(-10,10,100) …

no image

matplotlib で複数のグラフを並べて表示する方法

plot.subplots() でグラフの縦方向と横方向の数を指定する。 例 import numpy as np from matplotlib import pyplot as plt x1 = …