集合初始化

列表和集合 / 集合(Set)

int_set = {1, 2, 3}
str_set = {"one", "two", "three"}
# No order: sorted() keeps the print stable
str_sorted = sorted(str_set)
# str_sorted is ['one', 'three', 'two']

# Empty set: {} would be a dict
empty_set = set()
# empty_set is set()
not_set = {}
# type(not_set) is <class 'dict'>

# Any iterable, repeats are dropped
from_list = set([1, 2, 2, 3, 3, 3])
# from_list is {1, 2, 3}

print(f'{int_set = }')
print(f'{str_sorted = }')
print(f'{empty_set = }')
print(f'{type(not_set) = }')
print(f'{from_list = }')