4. Concepts about variables and assignment¶
Variables are used to store values and name an area of the computer’s memory
The symbol for assignment is the equals sign (
=
)
Like in mathematics, we pass parameters or values to a function using parentheses
A function
f(x)
, wheref
is the name of the function andx
is a parameterIn the previous example,
print
is the name of the function anda + b
is the value passed as a parameterWe can also use the interactive mode Try it here!
The first two lines do not print anything to the screen, so only the result of the third line is shown
4.1. Other alternatives¶
You may wonder why we create two variables,
a
andb
, to add two numbers?We could have achieved the same result in several ways.
What is the difference between the first way and the last two?
The first case includes the logic we used to obtain the result
This way, we explicitly state the algorithm we used mentally to solve this problem
In the last two cases, we simply command the computer to print something specific, without making clear the logic to arrive at that result.