5.4. Sets
内容纲要:
1. 用{}创建含有多个元素的几何
2. 用set函数创建几何 (set()创建空集)
3. set常用的运算符号
4. 用解析comprehension方法创建集合
Python also includes a data type for sets. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.
Curly braces or the set()
function can be used to create sets. Note: to create an empty set you have to use set()
, not {}
; the latter creates an empty dictionary, a data structure that we discuss in the next section.
Here is a brief demonstration:
Similarly to list comprehensions, set comprehensions are also supported: