python3

python3 で辞書(dictionary)を削除する

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

clear() することによって、辞書が存在した状態のまま、キーと値をすべて削除することができる。

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

結果

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

-python3
-

執筆者:


comment

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

関連記事

no image

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

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

no image

python3 で、配列の最大値のインデックスを1つ求める方法

配列の index() メソッドを使うと、その値のインデックスを求めることができる。 最大値を求めるメソッド max と組み合わせて使う。 例 arr = [2,4,5,10,8,-3] in …

no image

python におけるシフト演算子(<< と >> )の使い方

32 = 2^5 なので、 << 1 とすると数値は2倍され、 >> 1 とすると数値が2分の1となる。 例 print(32 << 0) print(32 << …

no image

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

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

no image

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

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