What's the difference between () vs [] vs {}?

后端 未结 4 753
轻奢々
轻奢々 2020-12-13 04:56

What\'s the difference between () vs [] vs {} in Python?
They\'re collections? How can I tell when to use which?

4条回答
  •  囚心锁ツ
    2020-12-13 05:18

    () - tuple

    A tuple is a sequence of items that can't be changed (immutable).

    [] - list

    A list is a sequence of items that can be changed (mutable).

    {} - dictionary or set

    A dictionary is a list of key-value pairs, with unique keys (mutable). From Python 2.7/3.1, {} can also represent a set of unique values (mutable).

提交回复
热议问题