*的使用技巧
# *的使用技巧
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)