John_Smith = {name: "John Smith",}
error:
name 'name' is not defined
It seemed as if the nether grasped onto my flimsy body and swing me all around a couple of times before setting me down only to step on me, splattering my brain in the process.
Nah, computers just don't like it if they don't understand what you're saying.
They get grumpy and mumble an error, hoping you understand it and fix whatever is wrong, to make them happy again :)
To understand what is happening, let's take a step back, and use numbers instead of strings, since they are less confusing.
34
As you (hopefully) know, 34 is a number. It is one of the integer values that we have. We call such a thing a literal, since you literally write the value. Compare with 1+6+8+1+4+6+3+2+1+2. This also has the value 34, but it is not the literal value 34, you have to perform computations before you can conclude it's also 34.
With strings, the rule of a literal value is that you type text, and add either a pair or ' quotes or a pair of " quotes around it.
So in your line, "John Smith" is a string literal (it has a pair of " quotes around it), and name is not a literal (neither ' nor " pair of quotes there).
The error is however caused by something different, namely variables. Let's first do this with numbers:
i = 1
What is the value of i + 2 ?
I hope you agree it's 3. Just above it, I wrote that i equals 1, so you can replace the "i" in i + 2 by "1", which gives you 1 + 2, which is 3 after an addition.
The "i" here is a variable, a name that represents a value (when I say i I mean the value 1).
Now this one
What is the value a + 5 ?
The answer is "I don't know, since you didn't give me the value of a!"
In other words, we cannot compute anything if we don't have all the information.
Now back to your line:
{name: "John Smith",}
What is name here?
Above we concluded it is not a string literal (it has no ' or " quotes around it).
Therefore, it must be a variable. However, your code has no value assigned to the variable name !
The computer is just as confused about "name", as you were about my "a", gets grumpy, and it spits out an error:
NameError: name 'name' is not defined
The 'name' thing refers to your name in the line of code, and it says it's not defined, which is correct, as you didn't make a variable called name , eg by doing
name = "the name is"
{name: "John Smith",}
The first name in the error line is somewhat unfortunate, but it indicates the computer doesn't know at all what you mean by name in the line of code.
It cannot say 'variable', as it has no idea what name is, or what it is supposed to be.
Adding the ' name = "the name is" ' line is one way of solving the problem, but there are many more. In this case, I think you meant to have a string literal with the text name which you write as
"name"
(the pair of quotes indicates it's a string literal).
That leads to
{"name": "John Smith",}
Last but not least, there is no difference between ' quotes and " quotes. "name" and 'name' are the same thing. Use what you prefer, or like me, use whatever mood you're in :)
PS About the associative array, the {} thing is a dictionary (dict in pythoneese), and it's official name is an associative array, just like 34 has the official name literal.
Don't worry too much about those things for now, have fun programming things. When you have more experience and do more study, they will come back to you.