python__实参前加*和**的(拆包)功能
print('--------元组打散--------') tup=(1,2,3) print(tup) print(*tup) print('--------列表打散--------') list=[1,2,3] print(list) print(*list) print('--------字符串打散------') str='hello' print(str) print(*str) print('--------字典打散--------') def func_dic(name,age): print(name,age) dic={'name':'sanxi','age':20} #打散的只是值 func_dic(**dic) print(**dic) #报错
结果:
--------元组打散-------- (1, 2, 3) 1 2 3 --------列表打散-------- [1, 2, 3] 1 2 3 --------字符串打散------ hello h e l l o --------字典打散-------- sanxi 20