With print, that dictionary is less readable:
>>> print(user)
{'name': 'Trey', 'languages': ['Python', 'JavaScript'], 'address': {'city': 'San Diego', 'state': 'CA'}}
Pretty-printing is great for data structures that are too long for one line. It's especially helpful for nested data structures.
🧵 (2/4)
![What's New in Python
Every supported version, 3.11 to 3.15
Python 3.15 — supported until October 2031
[*row for row in rows] # flatten nested lists
lazy import json # load json on first use
MISSING = sentinel("MISSING") # nicer than object()
frozendict(a=1, b=2) # an immutable dict
Python 3.14 — supported until October 2030
path.copy(target) # pathlib.Path, also move
date.strptime(text, "%Y-%m-%d") # also time.strptime
except ValueError, TypeError: # parentheses optional
t"Hello {name}" # template strings
Python 3.13 — supported until October 2029
copy.replace(point, x=0) # copy with x changed
@warnings.deprecated("Use g()") # warn callers to switch
batched(rows, 3, strict=True) # error on a partial batch
python -m random 6 # roll a die
Python 3.12 — supported until October 2028
f"{", ".join(names)}" # reuse quotes in f-strings
type Point = tuple[int, int] # define a type alias
batched(names, 2) # loop in groups of 2
path.walk() # os.walk for pathlib.Path
Python 3.11 — supported until October 2027 (Safe for libraries today)
tomllib.load(file) # read TOML files
err.add_note("row 5") # note shown in traceback
class Color(enum.StrEnum): # members are strings
async with TaskGroup() as tg: # cancel the rest on error
The full printable cheat sheet: pym.dev/cheat-sheets
© Trey Hunner
Python Morsels](https://files.aleph.land/cache/media_attachments/files/117/441/909/513/742/691/small/6f2bbd2e0618dbe4.png)