Understanding variable scopes in functions

Report a typo

In a Python program, you have a function that sets a greeting message. The function is called 'greet()' and it contains a local variable 'greeting'. Creating another variable with the same name outside this function, you fill it with a different message. After you call the function and print the 'greeting' variable, there are two distinct messages. Understand the behavior of these two variables in different scopes and fill the blanks in the code to output the correct messages.

Fill in the gaps with the relevant elements
 greet():
    greeting = "Hello, User!"
     greeting
greeting = "Hi, User!"
(greet())
print(greeting)
lambdareturndefprintdebugclass

Create a free account to access the full topic