运行Python时,报错:
File "C:/Users/Administrator/untitled0.py", line 27, in <module>
for k,v in datateam:
ValueError: too many values to unpack (expected 2)
代码:
datateam={
'name':'wanger',
'pwd':'123'
}
lt=[]
url='https://www.baidu.com/index.html?'
for k,v in datateam:
lt.append(k+'='+v)
str_info='&'.join(lt)
print(url+str_info)
说明我的字典出错了
改:加上一个item(),因为字典是迭代器对象,无法直接进行用
datateam={
'name':'wanger',
'pwd':'123'
}
lt=[]
url='https://www.baidu.com/index.html?'
for k,v in datateam.items():
lt.append(k+'='+v)
str_info='&'.join(lt)
print(url+str_info)