python-序列解压

需求:取出一个序列tup中第一个和最后一个的值

input:
a,b,c,d=(1,2,3,4)   # 必须一一对应,否则报错
print(a,b,c,d)
a,*_,d=(1,2,3,4)    # *代表所有,即把剩余的所有的值赋值给_
print(a,_,d)

output:
1 2 3 4
1 [2, 3] 4

 

posted on 2019-11-06 15:16  别动我的锅  阅读(141)  评论(0)    收藏  举报

导航

levels of contents