Note - coding isn’t about memorization so you don’t need flash cards
Also note - GPT has no way to know if it’s totally lying to you
I don’t think your note on the card is quite right. Inside of the inner function you use the ‘global’ keyword to access and modify the variable a in the global scope, but the outer function still has its own local version of the variable a.
So actually ChatGPT is wrong in this instance. Your outer function is creating a brand new variable called a since it does not use the global a statement that will pull the global variable into the outer function. That is why it is 0 in the “outer2” print but it is 2 in the “main2” print.
Check out this, for example, where I add global a to the outer function:
def outer():
global a
def inner():
global a
a = 2
print("inner:", a)
a = 0
print("outer1:", a)
inner()
print("outer2:", a)
a = 1
print("main1:", a)
outer()
print("main2:", a)
It then has the output you expect because it is modifying the global variable a, not the local variable a created within the outer function that is in your original code.
I appreciate the answer and your example! Thank you!
It’s not about memorization per say, more so the method of studying called “active recall and spaced repetition”. Both of which I’ve used to pick up a N3 level of Japanese and Russian, and sometime down the line, Spanish.
It’s a scientifically backed method of learning that trains the brain to look at certain patterns and easily differentiate between them, amoung other benefits!
I work 13 hours days, so I have only so much time to sit down and code and being able to break down problems by doing my own cards or someone else’s debugging on the fly helps a ton with being able to recall the information at any time I might need it!
Possibly! Everyone has their own opinion, and I’m going off past experience and that of several youtubers who are also in the industry, who have also used the method, as it brought me back to using it with code.
There are even plugins that work with VSCode and Anki cards.
But; I’m not using it to learn theory! I’m learning it to get used to seeing code and be able to quickly deconstruct code into smaller parts to be understandable to myself.
It’s worked for me so far, and that’s what’s best for anyone studying anything.
I “memorize” structure and “Syntax”/grammar from reading it, but flash cards won’t help you write it.
I’m absolutely better at reading code and understanding what’s going on, than I am at sitting down and writing it out due to not having as much practice as the time between work and code can be days to weeks.
I absolutely look up more than my fair share of concepts when making anything.
When using Java to mod minecraft I had to look a ton syntax and methods up as when I was making games with unity C# and simply dragging files to parent them to a game object was extremely different. Flash cards with anki did a ton of reference work for me there.
Everyone has something that works for them! This just has worked for me.
I’ll give that a read when I have the chance, I appreciate it!
That may be. All I could possibly tell you is outside game dev I’ve had very limited code exposer and things like Global and Nonlocal are new to me and I’ve only seen them through things like flash cards.
And now through reading and spaced repetition, if I ever have use of them, I know what they do and will be able to work off that knowledge.
They may go into different parts of the brain, but I got the results I needed for now and can build off those with more practical experience when the need arises! Which suits my own needs. And I figure that’s what coding is about, using it for things that are needed to be done.