I think this quiz question in Python is wrong

One of the quizzes in Python asks you this:
“What is Python syntax for creating a variable and setting it equal to the number 10 ?”

The answer it gives is new_variable = 10

What’s wrong is the grammar. The variable isn’t equal to 10. 10 is a VALUE that is stored in a piece of memory called in this case new_variable. new_variable does not EQUAL 10. 10 is a value stored in new_variable, that’s all.

It’s annoying too because the equal sign in Python (=) doesn’t equal anything that’s (==) instead the better word is assign.

I think you should change the phrasing to that quiz. When I think through code and use the word equal to things that are not, it messes with logic.

2 Likes

‘setting it equal’ vs ‘assign’ doesn’t seem like an argument worth anyones time nor energy.

Worth the Time and energy of a professional yes it would be, of some lazy sod, no, that never is.
= does not mean equal, so why teach people the wrong thing in python code.
== means equal
A value is contained in the variable, the variable does not equal the value.
That’s a fact. So given its wrong to be inaccurate in a training course, given this is SOFTWARE it takes all of what… 1 minute to fix?? Fix the thing and quit being sloppy.

There’s about a million pedantic holy wars you can fight in programming.

1 Like

This is an interesting point! It’s more than likely that I wrote this quiz question. The expectation, for me, was that people who are learning programming at this level aren’t usually making the distinction that you make. “A variable that is set equal to 10” sounds very similar to “A variable that has been assigned the value 10”. Your point is true, though, that the former is inaccurate given the way the programming language logic works.

At this point in the curriculum, we’re trying to make sure that the algebraic concept of a variable is understood. Python variables and algebraic variables don’t have a perfect correspondence, but algebra offers insight into the intention variables serve in programming languages. In my efforts to make sure the correspondence between new_variable (the name of the variable) and 10 (the value being assigned to the variable) explicit, it seems I’ve glossed over some truth about what a variable is in Python.

I hope you can understand that this slip-up was a result of trying to express this connection in a beginner-friendly way, but I’ve updated the question to use the language you suggested (because it is both more honest and accurate).

7 Likes

I really respect this reply.
I know some would call this pedantic, but in my field I’m a trainer.
I take disadvantaged kids and promise them a job of between 55-65K at the end of 4 months training. And I deliver. As part of validation, the kids compete against University Bachelors and Masters of It Graduates when evaluated side by side by large companies here in Australia, the kids totally destroy them technically, in critical thinking and working with people skills.
The reason why - is unlike the University I cut off bloated irrelevant content, keep things lean and make sure all the basics are accurate, factual and have a logic flow.
Though they learn less (although this is inaccurate, rote learning isn’t learning) they learn it well so they can easily extrapolate more complex ideas because the basics are thoroughly understood.

I like this Python much more than JavaScript by the way, JavaScript seems like they take committee votes on how it’s supposed to work.

1 Like

I think this is the result of being so interwoven with W3C, WHATWG, ECMA, and all the related working groups under those umbrellas. One wouldn’t think Python to be devised in so restrictive an environment. It looks more peer driven. Just an opinion, mind.

As far as containment is concerned, here is a line of thinking that could have negative and positive consequences. Once we stop thinking of variables as containers we graduate to different level of thinking where assignment is more purely expressed.

Python as we know will not store two of the same values in two different places. There is just the one value. A variable is akin to a tag we hang on the hook representing that value. The first couple hundred small integers even have their own special table so those values will never reside in memory on their own.

Thanks for bringing up this topic, @cakarena, and thank you for your honest and responsive reply, @timlmul. I hope this topic continues down the rabbit hole of variables and pointers. Would really love to see this drawn out a little more in technical terms so that learners who are moving up the ladder have a place to broaden their perception and learn more about the inner workings and foundation of the language. Great stuff!

Edited

3 Likes

A quick illustration about mutually shared values between data structures…

>>> a = [7, 6, 13, 42]
>>> b = [3, 14, 17, 42]
>>> id(a[3])
1725512096
>>> id(b[3])
1725512096
>>> a = 7, 6, 13, 42
>>> b = 3, 14, 17, 42
>>> id(a[3])
1725512096
>>> id(b[3])
1725512096
>>> id(a[0] * a[1])
1725512096
>>> id(b[0] * b[1])
1725512096
>>> c = {"meaning of life": 42}l
>>> id(c['meaning of life'])
1725512096
>>> s = {7, 6, 13, 42}
>>> id(max(s))
1725512096
>>> 

Thanks for this, I had to look up ‘id’

d() function in Python

Introduction
id() is an inbuilt function in Python.
Syntax:

id(object)

As we can see the function accepts a single parameter and is used to return the identity of an object. This identity has to be unique and constant for this object during the lifetime. Two objects with non-overlapping lifetimes may have the same id() value. If we relate this to C, then they are actually the memory address, here in Python it is the unique id. This function is generally used internally in Python.

I liked playing with that in CDM prompt. I’m just learning Python, the returns the value at that point in the list, I got confused but the count begins with 0 not 1, like lifts in New Zealand and Australia. I must look up why. I thought that was interesting.

3 Likes

You’re welcome. Glad to see you follow up.

What you may find is that it is for the simplicity it gives loops and conditionals.

Wikipedia is a good place to start…

https://en.wikipedia.org/wiki/Zero-based_numbering

The [] is called the subscript. The same syntax applies to lists, tuples, strings and dictionaries, though the latter expects text, not a serial index value.

Great that you dug into this, too. Picking this up early is a sure way to speed up learning.

3 Likes