【python入門到放棄】字典元素的循環打印


#定義一個字典
dic = {'name':'wusan','pwd':27,'sex':''}

#循環打印出默認的字典元素,實際為key值
for item in dic:
    print(item)

#循環打印出字典中的key值
for item in dic.keys():
    print(item)

#循環打印出字典中的value值    

for item in dic.values():
    print(item)

#循環打印出字典中的鍵值對
for item in dic.items():
    print(item)

#循環分別打印出字典中的key值和value值
for k,v in dic.items():
    print(k)
    print(v)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM