Computer Science

What is the output of the program given below?

x = 50
def func(x):
    x = 2
func(x)
print('x is now', x)
  1. x is now 50
  2. x is now 2
  3. x is now 100
  4. Error

Python Functions

3 Likes

Answer

x is now 50

Reason — The output of the program will be x is now 50. This is because the variable x inside the func function is a local variable, so any changes made to it inside the function do not affect the global variable x defined outside the function. Therefore, after calling the func function, the value of x remains unchanged and is still 50 when printed.

Answered By

1 Like


Related Questions