Test Index

Functions in Python Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 13 of 23
Marks: +1, -0
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 :
[CBSE 2024 Set 4]
Solution:  
Concept:
A parameter is a local variable of the function. Changing it inside the function does not change a global variable of the same name.
Solution:
Global a = 20.
convert(10): inside, local a = 10, b = 20, local a = 30. Nothing is returned and the global a is untouched.
print(a) prints the global a, i.e. 20.
Key point: 30 would be printed only if the function used global a or returned the value and it was stored in a.
Answer:
Option B (20)
© examsnet.com
Advertisements
Go to Question: