变量解包
username = ["zaygee", "hoan"]
a, b = username
print(a, b) # zaygee hoan
vara, varb = 0, ''
print(vara, varb) # 0,
星号表达式
variables 作为变量名,会贪婪的捕获多个值,并将捕获到的内容作为列表赋值给variables _ 一般用于作为无用占位
# 列表
a, *b, c = [1, 2, 3, 4, 5, 6]
print(a, b, c) # 1 [2, 3, 4, 5] 6
a, *_ = [1, 2, 3, 4, 5, 6]
print(a) # 1
# 字典
a, *b, c = {"a": 1, "b": 2, "c": 3, "d": 4}
print(a, b, c) # a ['b', 'c'] d
# 元祖
a, *b, c = (1, 2, 3, 4, 5)
print(a, b, c) # 1 [2, 3, 4] 5
布尔值作为整数使用
print(sum([True, True])) # 2
print(sum([False, False, False])) # 0