辞書の作成・操作

ソースコード
                    #coding:utf-8
                    #連想配列、辞書(Dictionary)2025/2/5
                    #key:value-→item
                    import os
                    os.system('clear')

                    #辞書を作成する 辞書は複数の方法で作成できます。

                    #方法1:直接代入
                    student = {"氏名":"山田亮","数学点数":87, "WEB":90}
                    print(student)

                    #方法2 dict()コンストラクタ
                    student=dict(氏名="山田亮",数学点数=87,WEB=90)
                    print(student)

                    #方法3 ダブルのリストから作成
                    student= dict([("氏名","山田亮"),("数学点数",87),("WEB",90)])
                    print(student)


                    print(student["氏名"])

                    print(f'学生氏名は={student["氏名"]} WEBの点数は{student["WEB"]}です。')
                    print("優秀ですね")

                    #キーが存在しない場合にエラーを避けるためにget()メソッドを使用します
                    print(student.get("pythonPG"),"このデータはありません")

                    #アイテムの追加または、変更する。新しいキーと値のペアを追加するか、既存のキーの値を更新します。
                    student["pythonPG"] = 100
                    student["数学点数"] = 85
                    print(student)

                    #ネスト(nest 鳥の巣)

                    student={
                        "立野肇":{"年齢":20,"点数":"A"},
                        "赤水瞬":{"年齢":19,"点数":"B"},
                        "立花明人":{"年齢":21,"点数":"A"}
                    }

                    print(f'学生名簿{student}')
                    print(student["立花明人"]["年齢"])

                
実行結果