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:41] – [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> | ||
- | thisdict | + | exampledict |
- | "brand": "Ford", | + | "class": "Modified Hall", |
- | "model": "Mustang", | + | "engine": "Witherslack Hall", |
- | "year": | + | "built": |
} | } | ||
- | for x in thisdict: | + | for x in exampledict: |
- | print(thisdict[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) | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | Modified Hall | ||
+ | Witherslack Hall | ||
+ | 1948 | ||
+ | </ | ||
==== 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.1739529687.txt.gz · Last modified: by andrew