Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 25)
25.
What will be the output of the following Python code?
def func(x):
    x += 1
    return x

x = 5
result = func(x)
print(x, result)
5 6
6 6
5 5
This code will result in an error.
Answer: Option
Explanation:
The function modifies its local copy of x, and the global x remains unchanged.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.