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