I'm taking a course to brush up on my Python skills. (Which aren't many, but so far what I've seen is fairly basic/review. I suspect by the end of the week we'll be learning things that are new to me?) You don't need to know a lot about programming to follow this: (normal is input, bold is output)
x = 10
(this tells the computer what x is. x is now 10)
x + 2
12
(the computer added 2 to x, which is 10, and got 12).
x = 5
(now I give the computer a new value for x. it forgets about the 10 and goes with 5 instead)
x + 2
7
(get it?)
Anyway we're supposed to be learning/reviewing what is a "list" versus a "tuple" etc. right now. But this instructor likes to get sidetracked on how the "memory" works in Python, "stacks" versus "heaps" etc. Again, don't worry too much about what all this means.
x = (1,2)
(I told the computer I want x to be a "tuple," like an ordered pair on a graph.)
y = [0, (5,6), x]
(I made a list called y, whose third element is the tuple called x.)
x = 5
(the same way we did above, we forget that x used to be a tuple, now it's the integer 5. tuples and integers are different "types," but that's okay, x can be anything.)
y[-1]
(asking the computer to output the last element in the list y. course pauses, thinks about what this should be.)
The answer is...
(1,2)
because at the time we defined y, the last element was x, and at that time, x represented (1,2). Even though we've changed x since then, we haven't done anything to y. So as far as the computer knows, the last element of y is (1,2).
Now, this kind of abstract thinking is necessary not just in Python, but I would assume pretty much any programming language, to be able to keep track of what your variables represent and why. And, because I'm an abstract-thinking person and have experience with Python, this is pretty straightforward for me.
But this also seems to be a more 21st-century form of the Sally-Anne test! (Which...doesn't seem to be that reliable a metric anyway, perhaps this is a case in point.)
x = 10
(this tells the computer what x is. x is now 10)
x + 2
12
(the computer added 2 to x, which is 10, and got 12).
x = 5
(now I give the computer a new value for x. it forgets about the 10 and goes with 5 instead)
x + 2
7
(get it?)
Anyway we're supposed to be learning/reviewing what is a "list" versus a "tuple" etc. right now. But this instructor likes to get sidetracked on how the "memory" works in Python, "stacks" versus "heaps" etc. Again, don't worry too much about what all this means.
x = (1,2)
(I told the computer I want x to be a "tuple," like an ordered pair on a graph.)
y = [0, (5,6), x]
(I made a list called y, whose third element is the tuple called x.)
x = 5
(the same way we did above, we forget that x used to be a tuple, now it's the integer 5. tuples and integers are different "types," but that's okay, x can be anything.)
y[-1]
(asking the computer to output the last element in the list y. course pauses, thinks about what this should be.)
The answer is...
(1,2)
because at the time we defined y, the last element was x, and at that time, x represented (1,2). Even though we've changed x since then, we haven't done anything to y. So as far as the computer knows, the last element of y is (1,2).
Now, this kind of abstract thinking is necessary not just in Python, but I would assume pretty much any programming language, to be able to keep track of what your variables represent and why. And, because I'm an abstract-thinking person and have experience with Python, this is pretty straightforward for me.
But this also seems to be a more 21st-century form of the Sally-Anne test! (Which...doesn't seem to be that reliable a metric anyway, perhaps this is a case in point.)
no subject
Date: 6/2/20 06:53 pm (UTC)On the Sally-Anne test: I gave my (NT) child A. and (ASD) child E. a variant of this test which had all kinds of flaws, but it's the one I gave them, so whatever. A. was 3 at the time, and E. was 8. Early in the morning before their dad was up, I showed them a box of crackers and put pencils in it, and asked them what Daddy would think was in it when he woke up.
A. thought about it and after a moment answered triumphantly, "Crackers!!" and was very pleased with this and totally wanted to do this experiment when D got up.
E. said, "I don't know! How would I know?" Which was not one of the answers I was expecting, and which I found very interesting! And it's very in keeping with how she thinks about things: if you haven't very clearly specified the parameters of interaction she will have trouble because she won't make assumptions others would normally make. This also makes her a really excellent logician :)
no subject
Date: 6/2/20 08:07 pm (UTC)High-fives to E., that's awesome :D
(Edit: I have not done anything abstract enough in Python to actually need to know about the different kinds of memory. Maybe someday.)