Just some clarification


#1

Please leave the following link in the post so we can find the unit module, else replace it with a link to the exact lesson:

Strings and Console Output

Hi. Just need some clarification. I tried defining a variable after a print command to display the content of that variable and it worked!
If codes are indeed read line by line, how did that happen? I was honestly expecting a bug


#2

@drhyke,

Not defining a variable before attempting to displaying its value does constitute an error. However, Codecademy maintains a memory cache for variables. The cache persists across submissions while you are working on a particular exercise, and may enable you to submit code successfully that would ordinarily raise an error.

If you submit this to Codecademy …

brian = "Hello life!"
print brian

… then change it to this in the same editing session …

print brian
brian = "Hello life!"

… it will execute successfully both times. That it because brian gets cached during the first submission.

If you post your problematic code, along with your initial version of it, we may be able to explain why you did not receive an error.


#3

Oh…It’s clear now. Thank you.


#4

Just… slightly objecting to calling it caching, it’s not wrong, but what’s happening is that the same python interpreter is kept alive, so you’re adding code at the bottom each time you run it. Nothing fancy is happening, it’s just how CC chooses to run your code.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.