User Tools

Site Tools


python:python-code

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
python:python-code [14/02/2025 10:45] – [Print all the values - version 2] andrewpython:python-code [14/02/2025 10:48] (current) – [Print both keys and values] andrew
Line 64: Line 64:
 ==== Print both keys and values ==== ==== Print both keys and values ====
  
 +Using the "items()" function to return both the value and the key for wach item.
  
 +<code python>
 +exampledict = {
 +  "class": "Modified Hall",
 +  "engine": "Witherslack Hall",
 +  "built": "1948"
 +}
 +for x,y in exampledict.items():
 +  print(x, y)
 +</code>
 +
 +<code>
 +class Modified Hall
 +engine Witherslack Hall
 +built 1948
 +</code>
  
  
python/python-code.1739529954.txt.gz · Last modified: by andrew

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki