Tag Archives: Python Reference

Python – Everything is a Reference

For school, I must learn the Python programming language (not very excited about it). Don’t get me wrong, there is nothing bad about Python, I am just a die-hard C style programmer. My first language was C#, then I learned C++, and then a little bit of C. So, a whole different style of a programming language is a little off-putting to me. As I was learning, however, I came to a realization. Every variable in Python is a reference.

In the C style of languages, in general, a variable is thought of like a chunk of data. You can make references to that chunk of data, you can move, copy, and point to that chunk of data. However, the mental model of a basic variable in C style languages is a chunk of data. This is not the case in Python. All a variable is in Python is a pointer. That pointer can point to anything. Unlike a C style pointer, where it has a type. It is pretty much a void pointer that you don’t have to cast to use.

Coming to this realization just made Python a lot simpler. It was this little piece of the puzzle I was missing. I kept trying to think in terms of C#; while this can help in some ways, the mental model is not compatible. Apples to oranges as they say. I figured I would share this to maybe help another C programmer learning Python get a better grip on the language.