Teach Your Kids To Code: A Parent-friendly Guide to Python Programming

(vip2019) #1

38 Chapter 3


The fact that we can rely on a computer to answer correctly
and quickly every time we give it proper input is one of the most
powerful aspects of coding. We can count on computers for fast,
accurate calculations, as long as we program them correctly in a
language they understand. That’s what you’re learning to do as
you learn to code in Python.

Variables in the Python Shell


As we’ve discussed, the Python shell gives us direct access to the
programming power of Python without having to write entire
stand-alone programs. We can even use variables, like x and my_age,
when we’re typing in the Python shell; we just have to assign them
values, as you learned to do in this chapter’s opening example.
If you type x = 5 at the command prompt (>>>), Python will
store the value 5 in memory as the variable x and will remember it
until you tell Python to change the value (for example, by entering
x = 9 to give x a new value of 9 ). See the examples in the Python
shell in Figure 3-4.

Figure 3-4: Python remembers our
variable’s value for as long as we want.
Free download pdf