Tutorials Exercises Get Certified Services Bootcamps Spaces Sign Up Log in
Dark mode
Dark code
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP BOOTSTRAP HOW TO W3.CSS C C++ C# REACT R JQUERY DJANGO
Python Intro
Python Get Started ADVERTISEMENT
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Numbers
Python Casting
Python - Loop Dictionaries
Python Strings ❮ Previous Next ❯
Python Booleans
Python Operators
Python Lists
Python Tuples Loop Through a Dictionary
Python Sets
Python Dictionaries You can loop through a dictionary by using a for loop.
Python Dictionaries When looping through a dictionary, the return value are the keys of the dictionary, but there are methods to return the values as
Access Items well.
Change Items
Add Items
Example Get your own Python Server
Remove Items
Loop Dictionaries Print all key names in the dictionary, one by one:
Copy Dictionaries
for x in thisdict:
Nested Dictionaries print(x)
Dictionary Methods
Dictionary Exercise Try it Yourself »
Example
Print all values in the dictionary, one by one:
for x in thisdict:
print(thisdict[x])
Try it Yourself »
COLOR PICKER
Example
You can also use the values() method to return values of a dictionary:
for x in thisdict.values():
print(x)
Try it Yourself »
Example
You can use the keys() method to return the keys of a dictionary:
for x in thisdict.keys():
print(x)
Try it Yourself »
Example
Loop through both keys and values, by using the items() method:
for x, y in thisdict.items():
print(x, y)
Try it Yourself »
❮ Previous Log in to track progress Next ❯
ADVERTISEMENT
ADVERTISEMENT
Spaces Upgrade Newsletter Get Certified Report Error
Top Tutorials Top References Top Examples Get Certified
HTML Tutorial HTML Reference HTML Examples HTML Certificate
CSS Tutorial CSS Reference CSS Examples CSS Certificate
JavaScript Tutorial JavaScript Reference JavaScript Examples JavaScript Certificate
How To Tutorial SQL Reference How To Examples Front End Certificate
SQL Tutorial Python Reference SQL Examples SQL Certificate
Python Tutorial W3.CSS Reference Python Examples Python Certificate
W3.CSS Tutorial Bootstrap Reference W3.CSS Examples PHP Certificate
Bootstrap Tutorial PHP Reference Bootstrap Examples jQuery Certificate
PHP Tutorial HTML Colors PHP Examples Java Certificate
Java Tutorial Java Reference Java Examples C++ Certificate
C++ Tutorial Angular Reference XML Examples C# Certificate
jQuery Tutorial jQuery Reference jQuery Examples XML Certificate
FORUM | ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.
W3Schools is Powered by W3.CSS.