*的使用技巧
作者:互联网
# *的使用技巧
ages = [1, 2, 4, 8]
def drop_first_last(ages):
f, *m, last = ages
return sum(m) / len(m)
print(drop_first_last(ages))
# ############
records = [
['a', 1, 2],
['b', 'hello'],
['a', 'b', 'c']
]
def do_a(x, y):
print('a', x, y)
def do_b(s):
print('b', s)
for i, *j in records:
if 'a' == i:
do_a(*j)
elif 'b' == i:
do_b(*i)
records2 = ('a', '50', 111, (1, 23, 2020))
name, *_, (*_, year) = records2
print(name)
print(year)
标签:do,last,技巧,year,ages,使用,print,def 来源: https://www.cnblogs.com/fly-book/p/13385227.html