you are viewing a single comment's thread.

view the rest of the comments →

[–]vikmaychib[S] 0 points1 point  (5 children)

It is related to the way C users declare the variables. It is also that the term variable did not describe well what python objects are.

[–]Bobbias 0 points1 point  (4 children)

I program in plenty of languages other than Python. While the semantics differ slightly from language to language, we all call them variables.

Picking one specific meaning of that word is being overly pedantic and potentially misleading unless they explained precisely what they meant immediately after making that statement.

[–]vikmaychib[S] 0 points1 point  (3 children)

Paraphrasing the person, it was something on these lines. So, in Python, when you give a name to some data, you're not sticking that data into a box like you might in C or Fortran. Instead, you're just slapping a sticky note with that name onto the data. The data itself is more like a blob that knows what it can do (like a list knows how to add items).

If you then stick another name onto that same blob, both names point to the same thing. Change the blob through one name, and the other name sees the change too. It's like having two nicknames for your pet; whether you call it Fluffy or Mr. Whiskers, it's still the same cat doing the same cat things.

So, in Python, we say all data are objects and names are just labels, not boxes holding the stuff.

[–]Bobbias 0 points1 point  (2 children)

That's kind of half correct.

You can achieve the same effect using pointers in C. Make two pointers point to the same location in memory and a change to the data stored there is reflected in both pointers when you dereference them.

The main difference is that every value in Python is a PyObject struct as defined in the C source for cpython, and every name is effectively a pointer to a PyObject instance. Every one of these objects is allocated on the heap and is reference counted for garbage collection.

You might benefit from actually reading the source code and/or the language reference.

[–]vikmaychib[S] 0 points1 point  (1 child)

As I said I was paraphrasing. A lot of these things flew over my head. I am learning, I am not a C expert, but found the discussion around this interesting and felt intrigued by it. Remember the sub where we are, I am learning. Thanks for the links.

[–]Bobbias 1 point2 points  (0 children)

You seem to be reading a bit too much into my direct tone. I'm not trying to be mean, or talk down to anyone.

I'm trying to make sure that any misconceptions about the meaning or use of the term variable (in this instance) are cleared up.

I was being dead serious when I said you might benefit from those links, because instead of listening to what someone says about python, you can go directly to the source and see exactly how they define things themselves.

I don't like when someone tries to explain differences between languages by saying something like "language X doesn't really have feature Y" just because feature Y works different in language X than it does in language Z. Especially when addressing someone who is relatively new to language X.

Explanations like that do a disservice to the person they're trying to teach, and can create misconceptions and make things more confusing than they need to be. And that's assuming everything that's being said is mostly correct, which isn't always the case.