Question:

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 21, 2025
  • 10
     

  • 20
     

  • 30
     

  • Error
     

Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

In Python, variables defined inside a function are local to that function and do not affect variables outside the function. Here, the variable a inside the function convert()is a local variable, and its value does not modify the global variable a. Therefore, the value of a printed outside the function remains 20.

Was this answer helpful?
0
0