Computer Science – Programming concepts | e-Consult
Programming concepts (1 questions)
The output of this code will be:
Inside function: x = 5
Outside function: x = 10
Explanation:
The variable x is declared globally. Inside the my_function function, a new variable also named x is declared. This is a local variable. When print("Inside function: x =", x) is executed, it refers to the local variable x within the function, which has the value 5. However, the global variable x retains its original value of 10. The global variable is not modified by the local variable with the same name. Therefore, when print("Outside function: x =", x) is executed, it refers to the global variable x, which still has the value 10.