序列解包与链式赋值

注意:元组是可以省去()

a =1,
print(type(a)) #<class 'tuple'>
a = 1
b = 2
c = 3

c,d,e = 1,2,3

f = 1,2,3

print(type(f)) #<class 'tuple'>

f1,f2,f3 = f
print(f1,f2,f3) # 1 2 3

h = [1,2,3]
h1,h2,h3 = h
print(h1,h2,h3) # 1 2 3

h1,h2,_ = h

print(h1,h2) # 1 2
a = 1
b = 1
c = 1

# a,b,c = 1,1,1
# 还可写成
a=b=c=1

results matching ""

    No results matching ""