What would the following python code print out?
1 2 3 4 5 6 |
|
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The code gives a Traceback:
NameError: name 'andy' is not defined
Why? Because line 4 is executed before line 5 and when that happens, the interpreter has no clue what the variable
andy
refers to.There are two important things that are highlighted here, which I always mention while teaching newbies:
=
in programming is more often the same as a binding or an assignment, which is not the same in the way it is used in mathFollow up teaser