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

python3 で、すべて小文字かどうかを判定する方法

islower() 関数を使う。 例 print(‘abcde’.islower()) print(‘abcDe’.islower()) 結果 True False

no image

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

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

no image

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

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

no image

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

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

no image

matplotlib でcsv ファイルを読み込むとき、最初の行をスキップする方法

numpy の loadtxt で読み込む行を省略したい場合 スキップしたい行を # 等の記号でコメントアウトして、 loadtxt の comments = ‘#’ とすると …