()与[]与{}之间有什么区别? [英] What's the difference between () vs [] vs {}?

查看:128
本文介绍了()与[]与{}之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python中()与[]与{}之间有什么区别?

它们是集合吗?我怎么知道何时使用哪个?

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

推荐答案

()-元组



元组是一系列不能更改(不变)的项目。

() - tuple

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

列表是一系列可以更改(可变)的项目。

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

字典是键值对的列表,具有唯一键(可变)。从Python 2.7 / 3.1起, {} 也可以表示一组唯一值(可变)。

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).

这篇关于()与[]与{}之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆