x, y, z = 1, 2, 3
print(x, y, z)
x, y, z = 1, 2 会抛出异常
括号可加可不加
v_tuple = (False, 3.5, 'abc')
(x, y, z) = v_tuple # 等价于x, y, z = v_tuple
print(x, y, z)
x, y, z = range(3)
print(x, y, z)
x, y, z = iter([1, 2, 3])
print(x, y, z)
x, y, z = map(str, range(3))
print(x, y, z)
print((x, y, z))
a, b = 1, 2
a, b = b, a
print(a, b)
x, y, z = sorted([1, 3, 2])
print(x, y, z)
a, b, c = 'ABC'
print(a, b, c)
print((a, b, c))
x = [1, 2, 3, 4]
x[:3] = map(str, range(3))
print(x)
s = {
'a': 1,
'b': 2,
'c': 3
}
a, b, c = s.items()
print(a)
d, e, f = s # 默认是键
print(d)
print(*[1, 2, 3], 4, *(5, 6))
print(*range(4), 4)
print({*range(4), 4, *(5, 6, 7)})
print({'x': 1, **{'y': 2}}) # 字典解包要用**
g = ((i + 2) ** 2 for i in range(10)) # 创建生成器对象
print(g)
print(tuple(g)) # 将生成器对象转换为元组
print(list(g)) # 生成器对象已遍历结束,没有元素了
g = ((i + 2) ** 2 for i in range(10)) # 创建生成器对象
print(g.__next__()) # 使用生成器对象的__next__()方法获取元素
print(g.__next__()) # 获取下一个元素
print(next(g)) # 使用函数next()获取生成器对象中的元素
print(list(g))
g = ((i + 2) ** 2 for i in range(10))
for item in g: # 使用循环直接遍历生成器对象中的元素
print(item, end=' ')