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 でランダムな整数の配列を作る方法

random モジュールを使う。randint() の引数で、配列の最小値と最大値を指定できる。 例 import random random_arr = [random.randint(-2 …

no image

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

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

no image

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

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

no image

matplotlib で、線の種類を変更する方法

「linestyle = 」として、線の種類を指定することができる設定の詳細は、次のリンクを参照。 https://matplotlib.org/stable/gallery/lines_bars_a …

no image

python3 で文字列を入力させて受け取る方法

C言語で scanf のようなものを作るには、python では input() で実現できる。 例 print(‘xの値を入力してください’) x = input() print(‘xの値は ‘ + …