python学习:集合教程

Python95

1.集合

集合(set)是一个无序的不重复元素序列。

可以使用大括号 { } 或者 set() 函数创建集合,注意:创建一个空集合必须用 set() 而不是 { },因为 { } 是用来创建一个空字典。

该集合由不同的元素组成,因此即使其中的值重复,也会自动对其执行重复数据消除。

[En]

The collection is made up of different elements, so it will be deduplicated automatically even if the values in it are duplicated.

示例:

```python

s=set() # 创建一个空集合
s
set()
s={1,2,3}
s
{1, 2, 3}
s={'A','B','C'}
s
{'C', 'B', 'A'}

输入验证码查看隐藏内容

扫描二维码关注本站微信公众号 Johngo学长
或者在微信里搜索 Johngo学长
回复 svip 获取验证码
wechat Johngo学长