Question:medium

Observe the given Python code carefully:
a = 20
def convert(a):
    b = 20
    a = a + b
convert(10)
print(a)
    
Select the correct output from the given options:

Show Hint

To modify a global variable inside a function, use the global} keyword. Otherwise, changes to the variable inside the function are local and do not affect the global scope.
Updated On: Jan 13, 2026
  • 10
     

  • 20
     

  • 30
     

  • Error
     

Show Solution

The Correct Option is B

Solution and Explanation

In Python, variables declared within a function are scope-bound to that function and do not influence variables external to it. Consequently, the variable 'a' within the 'convert()' function is local; its modification does not alter the global 'a'. Thus, the output of 'a' outside the function retains its initial value of 20.

Was this answer helpful?
0

Top Questions on Miscellaneous