حلقه از طریق فرهنگ لغت(Loop Through a Dictionary)

می‌توانید با استفاده از یک دیکشنری حلقه بزنید
حلقه برای.


هنگام حلقه زدن از طریق فرهنگ لغت، مقدار بازگشتی کلیدهای آن است
فرهنگ لغت، اما روش هایی برای برگرداندن مقدارها نیز وجود دارد.




مثال


Print all key names in the dictionary, one by one:



for x in thisdict:
  print(x)





مثال


Print all values in the dictionary, one by one:



for x in thisdict:
  print(thisdict[x])





مثال


You can also use the values() function to
return values of a dictionary:



for x in thisdict.values():
  print(x)





مثال


Loop through both keys and values, by using the
items() function:



for x, y in thisdict.items():
  print(x, y)