def func(*args,**kwargs): print(args,kwargs) func(1,2,3,'hhh',name = 'cbb')
------------------------------
(1, 2, 3, 'hhh') {'name': 'cbb'}
函数内,调用:
def func(*args): print(args) list_1 = [1,2,3] func(list_1) ----------------------- ([1, 2, 3],)
# 调用加* def func(*args): print(args) list_1 = [1,2,3] func(*list_1) #结果是:(1, 2, 3)
函数外:
a,b,*c = [1,2,3,4,5] print(a,b,c) #1 2 [3, 4, 5]
a,*c,b = [1,2,3,4,5] print(a,b,c) ---------------------- 1 5 [2, 3, 4]
a,*c = range(5) print(a,c) ----------------- 0 [1, 2, 3, 4]
a,*c,b = (1,2,3,4,5,6) #元组 print(a,c,b) ------------------------------- 1 [2, 3, 4, 5] 6 #c 出来还是列表