Line 1: x = 42
A global variable x is set to 42.
Line 4–8: Function Definition
def func():
global x # Refers to the global 'x' global x tells Python: “When I refer to x in here, I mean the one outside the function.”
print('1. x:', x)
x = 23 # Modifies the global variable
print('2. x:', x)
Line 11: func() #Calls func():
Line 6: #prints 1. x: 42
Line 7: #sets x = 23 (updates the global x)
Line 8: # prints 2. x: 23
Line 12: print('3. x:', x) #Prints the updated value of global x, which is now 23
Final Output:
1. x: 42
2. x: 23
3. x: 23
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Donny_575
1 month, 1 week ago