liveBook · Manning

Binding

As explained in Learn AI-Assisted Python Programming, Second Edition

Name binding is the association of an identifier with the program entity or value it denotes.

A variable is a name that refers to a value. Use one whenever a program needs to remember a value for later, such as a function result or a user’s name. section 4.3.2 section 3.1.2

In Python, = assigns the value calculated on the right to the name on the left. It means assignment, not mathematical equality, and a later assignment can change what the variable refers to. section 4.3.2

Variables commonly help you:

  • Store a function’s returned value so it can be printed or used later. section 3.1.2
  • Hold input, such as text entered by a user. section 4.3.1
  • Update a value with assignments such as age = age + 5, age += 5, or age *= 2. section 4.3.2

Remembering and changing a value

age = 20 + 4 age = age + 5 print(age) # 29 The first assignment gives age the value 24. The second calculates 24 + 5 and assigns 29 to age. Simply evaluating age + 3 would not change age; another assignment is required. section 4.3.2

# call the larger function with the values 3 and 5
# store the result in a variable called result
# then print result
result = larger(3, 5)      #1
print(result)

See a variable capture a function’s result before print displays it. section 3.1.2

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Explains naming, assignment, reassignment, expressions, persistence, and augmented assignment, without descending into runtime internals.
Examples
Demonstrates storing function results, capturing a name from input, and updating age with ordinary and augmented assignments.
What it assumes
Teaches variables from zero while assuming only basic exposure to Python functions, values, and interactive prompts.
What you can do after
Builds simple Python statements that store, reuse, print, and update values during a program session.
How it connects
Connects variables with assignment, expressions, functions, parameters, arguments, return values, input, and Python value types.

Also explained in

Compare how 11 books explain binding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.