0
1

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 5 years have passed since last update.

pythonの()と{}の違い

Posted at

Djangoの勉強をしていたら括弧の使い方でエラーが出ていたので知識の整理のために()と{}の違いについておさらいしておきます。
コードを写経して書いていると見間違えで別の括弧を書いてしまうことがありました。
そこで、括弧の意味をしっかりと理解し直して、記述の段階でエラーに気づけるように備忘録として残しておきます。

():タプル
不変型 (immutable) で、要素が複数の型からなることもできる。
操作やインデックス (あるいは namedtuples の場合は属性)でアクセスすることが多いです。

{}:辞書、集合
辞書はキー(key): 値(value) のペアの集合であり、キーが (辞書の中で)一意である。
集合とは、値が一意である、順序づけられていない要素の集まり

以上の内容はpython公式サイトを参照した。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?