Created
June 13, 2018 08:46
-
-
Save martin-martin/76849ace2aba9595c47dbaa8ca5a4fb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = "Mycroft" | |
def print_name_box(): | |
print(name) | |
def smaller_box(): | |
''' | |
(re)assigning a variable within the same scope | |
overwrites the same variable from an outer scope | |
-> you cannot use it *before* assigning it, | |
if you assign it at all anywhere in that scope. | |
--TASK--: uncomment the below print() statement | |
and interpret the results when running it | |
''' | |
# print(name) | |
name = "Sherlock" | |
def smallest_box(): | |
''' | |
inner scopes always draw from the next-outer layer | |
after 'name' got overwritten, the name that will | |
be printed is NOT the global-scope name anymore | |
''' | |
print(name) | |
smallest_box() | |
smaller_box() | |
print_name_box() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment