Alterna · учебный материал

Change and assignment

34.1: Changed and embezzled: Short theory, one example, and Python step-by-step.

Что в этом материале

Содержание и основные понятия

Changed is the name associated with the current value. Python first calculates the right part of the assignment and then changes the connection to the left.
substance and practice
Grade 8
OGE No. 6
01
How it works.
The computer does not store "formulas on paper." It performs the string, calculates the right part and links the name on the left to the given object. This rule explains both the normal update of the meter and the exchange of two values.
Name.
The name of the variable is a label for the meaning. It does not have to match the mathematical designation.
Subject.
The number, string or list exists as values; several names may indicate one variable object.
The sequence.
Until the branches and cycles, the program runs the lines from top to bottom.
Scooting.
The second team with the same name does not complete the old meaning: it creates a new connection of the name to the result.
02
One example in execution
Start the short program and go over the lines. The visualiser only shows the code, current line, variables and output.
On the record
x = x + 1
First read the current value
x
and then the sum is calculated and then a name is calculated.
x
So the first line has to create
x
A parallel assignment first calculates the whole right part, so the exchange does not lose any value.
Algorithm map
Read from left to right, then run the code.
1
Start
2
Create Left and Right
3
Change values
4
Take out the pair.
5
End
03
Remember
Don't use a name until it's assigned: it'll be "Error."
The register is important: total and Total are different names.
For the meter, clearly set the initial value before the first update.
Syntax of this page
=
It's an action, not an equality test.
a, b = b, a
Simultaneous assignment: Both values on the right are given before the names on the left are changed.
print(...)
Prints the values. Several arguments are separated by a gap unless sep is specified.
+ и -
Creates a new numerical result; the starting numbers do not change themselves.

Structural map of textbooks