python_解包
1、解包直接把这个元组,list,集合按顺序进行传参,当然字符串也是可以的传参,只要不是key=value的格式都可以
此外:集合也是无序的,最好也不要用集合的方式
备注:解包出了的个数要与传参个数保持一致
#解包--list,元组,集合 def connect(ip,port,username,password): print(ip) print(port) print(username) print(password) info_list=['192.168.1.1',3309,'zhaozhao','123456'] info_tuple=('192.168.1.1',3309,'zhaozhao','123456') info_set={'192.168.1.1',3309,'zhaozhao','123456'} connect(*info_list) connect(*info_tuple) connect(*info_set)
2、字典方式解包
两个*号这种方式就可以用做字典传参
另外这种传参字典的key,必须和函数参数名称一样
dic={"name":"zhaozhao","password":"123456"} def dic_fun(name,password): print(name) print(password) dic_fun(**dic) /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 /Users/dongyf/Documents/python/besttest_study/test.py zhaozhao 123456