python:python-code
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
python:python-code [14/02/2025 10:43] – [Print all the values] andrew | python:python-code [14/02/2025 10:48] (current) – [Print both keys and values] andrew | ||
---|---|---|---|
Line 23: | Line 23: | ||
- | ==== Print all the values ==== | + | ==== Print all the values |
<code python> | <code python> | ||
Line 33: | Line 33: | ||
for x in exampledict: | for x in exampledict: | ||
print(exampledict[x]) | print(exampledict[x]) | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | Modified Hall | ||
+ | Witherslack Hall | ||
+ | 1948 | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Print all the values - version 2 ==== | ||
+ | |||
+ | This uses the Python " | ||
+ | <code python> | ||
+ | exampledict = { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | for x in exampledict.values(): | ||
+ | print(x) | ||
</ | </ | ||
Line 44: | Line 64: | ||
==== Print both keys and values ==== | ==== Print both keys and values ==== | ||
+ | Using the " | ||
+ | <code python> | ||
+ | exampledict = { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | for x,y in exampledict.items(): | ||
+ | print(x, y) | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | class Modified Hall | ||
+ | engine Witherslack Hall | ||
+ | built 1948 | ||
+ | </ | ||
python/python-code.1739529785.txt.gz · Last modified: by andrew