2022-04-26

You’ve made it to the end of the second part of this series, so let’s summarize:

Arrays, sets, tuples, and dictionaries let you store a group of items under a single value. They each do this in different ways, so which you use depends on the behavior you want.

数组,集合,元祖和字典,让你可以存储一组元素并赋值给一个变量,它们使用不同方式实现这一点,具体使用哪一种取决于你的需求。

Arrays store items in the order you add them, and you access them using numerical positions.

数组按照你添加的顺序存储元素,你可以用元素所在的数字位置访问元素,比如第0个元素

Sets store items without any order, so you can’t access them using numerical positions.

集合存储元素是无序的,你不能用数字位置访问元素,第0个元素不是固定的

Tuples are fixed in size, and you can attach names to each of their items. You can read items using numerical positions or using your names.

元祖大小是固定的,你不能增加名字或参数,你可以使用名称,或者数字位置访问具体的元素

Dictionaries store items according to a key, and you can read items using those keys.

字典根据key存储元素,你可以用key访问到对应的元素(一个key对应一个value)

Enums are a way of grouping related values so you can use them without spelling mistakes.

枚举可以用来列举一系列相关的值,这样你在使用枚举具体值是不会有拼写错误的

You can attach raw values to enums so they can be created from integers or strings, or you can add associated values to store additional information about each case.

你可以给枚举值指定原始值raw value,这样系统就知道他们的 具体类型,方便创建和存储。你也可以给他们每个枚举值指定关联值,用来提供更多的细节。比如下雨天rainyday,给他指定关联值降雨量。

你可能感兴趣的:(2022-04-26)