Hacker News new | ask | show | jobs
by yuuuuyu 1173 days ago
A variable in Python is quite a different beast from a variable in C though.
1 comments

Agreed; so the 20 books that start with "A variable is like an imaginary box you can put stuff into!", and then lingers on the concept with 4 pages of illustrations and analogies from your childhood, is not useful to me; whereas a book that tells me quickly about global and local scopes in Python, whether it passes variables by values or references, if variables are pointers or not, etc; would be lovely :)
In C, a variable has traditionally been a box (memory location) that you put things into. Possibly a box that can only contain pointers to other boxes. That mental model breaks down slightly with references that modern C++ prefers, but still is useful.

In python a variable is just a name. Assigments change what object this name references. But nobody is ever going to change which object this name references, unless you do it yourself. They can mutate the object, but not the name, if that makes sense.