person = {'Name':'Dustin','Age':19,'HasCar':True}
如何使用 for 回圈獲得以下輸出:
The key "Name" has the value "Dustin" of the type "<class 'str'>"
uj5u.com熱心網友回復:
像這樣使用items()函式來獲取鍵和值
person = {'name':'Dustin','Age':19,'HasCar':True}
for key,val in person.items():
print(f'The key "{key}" has the value "{val}" of the type "{type(val)}"')
輸出
鍵“name”具有“<class 'str'>”型別的值“Dustin”
鍵“Age”的值為“19”,型別為“<class 'int'>”
鍵“HasCar”的值為“True”,型別為“<class 'bool'>”
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/491058.html
上一篇:從excel中過濾資料
