Skip to content

Instantly share code, notes, and snippets.

@martin-martin
Created June 13, 2018 08:46
Show Gist options
  • Save martin-martin/76849ace2aba9595c47dbaa8ca5a4fb4 to your computer and use it in GitHub Desktop.
Save martin-martin/76849ace2aba9595c47dbaa8ca5a4fb4 to your computer and use it in GitHub Desktop.
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