Answer to Question #181891 in Python for FORTUNE AIDOO

Question #181891

Create your own Python code examples that demonstrate each of the following. Do not copy examples from the book or any other source. Try to be creative with your examples to demonstrate that you invented them yourself.



  • Example 5: Show what happens when a variable defined outside a function has the same name as a local variable inside a function. Explain what happens to the value of each variable as the program runs.

184 words


1
Expert's answer
2021-04-16T02:24:03-0400
def test():
    example_variable = "local value"
    print(example_variable)
example_variable = "global value"
"""
result of the operation print(example_variable)
In this case, the variable has a global scope will be displayed:
global value
"""
print(example_variable)
"""
test() function call result
A local variable is defined in the body of the function :
example_variable
execution print(example_variable) inside a function
In this case, the variable has a local scope and the local value 
of the function will be displayed:
local value

"""
test()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS