1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

python インスタンス変数でDictionaryとかListとかのサンプル

Last updated at Posted at 2019-11-14

python クラス内のインスタンス変数で配列とかDictionaryを宣言するサンプル

##作業環境
Windows 10
PyCharm

コード

急いでいるのでコードのみメモ。

class ClassTest():
    def __init__(self):
        self.t: Dict = {'東京':900, '横浜':300, '大阪':250, '名古屋':200, '福岡':150}
        self.u = dict(a=1, b=2, c=3)
        self.v: List[int] = [["はい", 50, 100], ["いいえ", 100, 100]]

    def __del__(self):
        pass   # デストラクタ

test = ClassTest()
print(test.t['東京'])
print(test.u['a'])
print(test.v[0][0])

実行結果

900
1
はい

##あとがき
 自分用のメモです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?