logging instead of print
print debugging is fine for five minutes. In real code, use logging. You
can turn messages up or down without deleting them, and each one carries a
level and a time.
The levels, from quiet to loud: DEBUG, INFO, WARNING, ERROR,
CRITICAL. logging.basicConfig(level=logging.INFO) sets up output once, at
the start of the program. Then messages below INFO are dropped.
Each module usually makes its own logger with logging.getLogger(__name__).
One detail interviewers like: logging takes %s arguments and formats them
lazily.
log.debug("cart %s", cart) # cart is only turned into text if DEBUG is on
log.debug(f"cart {cart}") # the f-string is built every time
For most code the difference is tiny, but for a hot loop or a huge object it matters.
Run it. Then change the level to logging.DEBUG and run again.