A match statement can compare a value against number literals, and negative numbers have always been accepted, so case -1: is valid. A leading plus sign was not. Writing case...
The array module stores numbers in a fixed C type rather than as individual Python objects. The type code chosen when the array is created determines how many bytes each...
A task group runs several coroutines together and waits for all of them to finish. Sometimes that is more work than necessary. When a group asks several sources for the...
Decoding JSON produces Python objects chosen by the json module, and every JSON array becomes a list. That is a reasonable default, but a list is mutable and therefore cannot...
Many functions take an optional argument and need to know whether the caller supplied it. The simplest way is to give the argument a default of None and check for...
A command-line tool built with argparse rejects invalid values and lists the accepted ones, leaving users to spot typos themselves. Python 3.14 introduced suggestions for likely intended values, but enabling...
A bytearray can be modified after it is created, so it is a convenient place to collect data piece by piece. When the data is complete, it usually has to...
When an attribute lookup fails, Python tries to help by naming a likely candidate. The suggestion appears at the end of the error message as a "Did you mean" clause...
When strptime parses a string, any components not specified in the format are filled in using default values. A format without a year produces a date in 1900, which is...
An import statement runs as soon as it is reached. The module is located, executed and placed in sys.modules, and the cost is paid whether or not the program ever...