Example
Dynamic Typing
Python allows changing variable type during program execution. This is dynamic typing.
Showing 11–20 of 53
Example
Python allows changing variable type during program execution. This is dynamic typing.
Challenge
Unpack an (id, item, mass_kg) tuple into three named variables and print a cargo manifest line, then fix the ValueError when the manifest adds a fourth field.
Example
Tuple unpacking assigns its elements to separate variables simultaneously.
Challenge
Turn the bare 9.81 and 1000 in a weight report into named constants without changing the output, then write a Mars version with constants from the start.
Challenge
…landing site as a (lat, lon) tuple, unpack it into two variables in one line and print both to four decimals, then show it the way maps do, with N, S, E and W.
Example
Operator ** allows accepting any number of keyword arguments.
Example
Operator * allows accepting any number of positional arguments.
Example
Namespaces isolate variables. Modules and functions create their own namespaces.
Example
The nonlocal keyword gives access to variables in the enclosing function.
Example
F-strings are a modern way to format text in Python. Insert variables directly into text.