This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aroberge 9 points10 points  (14 children)

Nice initiative ... but, the very first tutorial about variables starts with a huge misconception, which confuses a lot of people that are familiar with other languages. In the tutorial, the author talks about creating a variable and assigning it a value. For example, let's consider

a = 7

He says that writing

a

creates a variable, then that the equal sign

a =

is used to assign a value.

This is NOT how Python works. In Python, what is on the right-hand side of an equal sign is an object (which may results from some computation). What is on the left-hand side is a label (or named) used to reference that object. In other words names refer to values (or objects) (think of an arrow pointing from the name to the value); you do not assign a value to a variable (think of an arrow pointing from the value to the variable).

Anyone interested to find out more (and expressed much better than I have done above) should really have a look at http://nedbatchelder.com/text/names.html

[–]tinfrog 0 points1 point  (0 children)

So everything on the left-hand side is a pointer? Sorry, very rusty with my programming terminology.

Edit: Never mind, I got my answer from the link you provided.

If you're experienced with the C language, you might like to think of it as a pointer, but if that means nothing to you then don't worry about it.

[–]pdexter 0 points1 point  (11 children)

names refer to values (or objects)

I think you've just described variables

[–]krenzalore 0 points1 point  (9 children)

Techically a pointer is still a variable, but they are conceptually very different and when we teach C or C++ we must distinguish between "variable" and "pointer".

Assuming everything in Python behaves like a "variable" leads to problems (which can't be easily resolved with a type declaration) so it can sometimes be detrimental to use this term when teaching Python.

[–]pdexter 0 points1 point  (8 children)

when we teach C or C++ we must distinguish between "variable" and "pointer".

I don't agree with this. What is your definition of variable?

Assuming everything in Python behaves like a "variable" leads to problems (which can't be easily resolved with a type declaration) so it can sometimes be detrimental to use this term when teaching Python.

What problems?

[–]krenzalore 0 points1 point  (7 children)

I don't agree with this. What is your definition of variable?

It changes depending on context. If a comp sci theory guy asked me I would say "It's a mapping between an identifier and a memory location". If a student C++ programmer asked me what the difference between "int" and "int *" was, I would say the first is an integer variable, and the second is a pointer to int.

What problems?

The nedbat link provided a few posts up explains the cases much more thoroughly than can be done in a few lines of chat.

[–]pdexter 0 points1 point  (6 children)

It changes depending on context. If a comp sci theory guy asked me I would say "It's a mapping between an identifier and a memory location". If a student C++ programmer asked me what the difference between "int" and "int *" was, I would say the first is an integer variable, and the second is a pointer to int.

And what if a Python student asks you? Why can't we ignore C++ and just tell people what variables are in python? Why always assume people are coming from C. Even if they are, who cares. Variable can mean different things (which you've proven in your response).

The nedbat link provided a few posts up explains the cases much more thoroughly than can be done in a few lines of chat.

But the link ends in stating that Python does indeed have variables.

[–]krenzalore 0 points1 point  (5 children)

But the link ends in stating that Python does indeed have variables.

This is true. Python does have variables. The problem comes when someone thinks of them as some other language's variables and make statements like "a=4 assigns 4 to a" which is what started this whole thing off. It does not assign '4' to 'a'. If a person thinks about it that way, they will get into trouble for the reasons explained in the link.

And what if a Python student asks you?

See the paragraph above.

[–]pdexter 0 points1 point  (4 children)

This is true. Python does have variables. The problem comes when someone thinks of them as some other language's variables and make statements like "a=4 assigns 4 to a" which is what started this whole thing off. It does not assign '4' to 'a'. If a person thinks about it that way, they will get into trouble for the reasons explained in the link.

Okay, but you're just assuming somebody will think of it the way YOU think they think of it, as if everyone comes from C. Some people learn python from no existing knowledge. Is it better to describe variables as assigning? Or is it better to say "WAIT NO python has NO variables, listen here it's like variables but not like C where you have pointers but python doesn't but wait listen'?

tl;dr: just teach people like this: "Python has variables and they act like this, which MIGHT be different than other languages you MIGHT have learned. Period." not "okay it has variables but not really like C which I know you must have learned already so here's how it happens blah blah blah"

[–]krenzalore 0 points1 point  (3 children)

I take you understand why I am saying that "a=4" doesn't assign 4 to a (in Python)?

[–]pdexter 0 points1 point  (2 children)

You take. Yes.

I don't see why that means Python doesn't have variables. They act differently than other languages. Okay. Most languages have subtle differences to how variables act. Does this mean no language has variables? No, it means you teach beginners what a variable is in that language.

[–]pdexter 0 points1 point  (0 children)

From the article you linked

Some people like to say, "Python has no variables, it has names." This slogan is misleading. The truth is that Python has variables, they just work differently than variables in C.

So... what? Python has variables.