English

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:

Advertisements

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:

Options

  • 10

  • 20

  • 30

  • Error

MCQ
Advertisements

Solution

20

Explanation:

The convert function changes the local variable 'a' value, which serves as the function's formal parameter. The printed value is the global variable 'a' value, which remains unchanged at 20.

shaalaa.com
  Is there an error in this question or solution?
2023-2024 (March) Set 4
Advertisements
Share
Notifications



      Forgot password?
Use app×