解包

 1 def connect(ip,port,username,passwd):
 2     print('ip:',ip)
 3     print('port:',port)
 4     print('username:',username)
 5     print('passwd:',passwd)
 6 
 7 l = ['127.0.0.1',3306,'root','123456']
 8 tup = ('127.0.0.1',3306,'root','123456')
 9 se = {'127.0.0.1',3306,'root','123456'}
10 str = '127.0.0.1',3306,'root','123456'
11 dict = {'passwd':'123456','port':'3306','ip':'127.0.0.1','username':'root'}
12 connect(*tup) # 元组 解包
13 connect(*l)   # list
14 connect(*se)  #集合是无序的,结果会错乱
15 connect(*str) #字符串
16 connect(**dict) # 字典是key:value模式,要用2个星号**
C:ProgramDataAnaconda3python.exe E:/cnz/day2/day4/解包.py
ip: 127.0.0.1
port: 3306
username: root
passwd: 123456
ip: 127.0.0.1
port: 3306
username: root
passwd: 123456
ip: 3306
port: 123456
username: root
passwd: 127.0.0.1
ip: 127.0.0.1
port: 3306
username: root
passwd: 123456
ip: 127.0.0.1
port: 3306
username: root
passwd: 123456

Process finished with exit code 0
原文地址:https://www.cnblogs.com/hujc/p/11760241.html