Class - 12 CBSE Computer Science Important Output Questions 2025
What will be the output of following program ?
num = 1
def myfunc():
num = 10
return num
print(num)
print(myfunc())
print(num)
Python
Python Functions
20 Likes
Answer
1
10
1
Working
num = 1— This line assigns the value 1 to the global variablenum.def myfunc()— This line defines a function namedmyfunc.print(num)— This line prints the value of the global variablenum, which is 1.print(myfunc())— This line calls themyfuncfunction. Insidemyfuncfunction,num = 10defines a local variablenumand assigns it the value of10which is then returned by the function. It is important to note that the value of global variablenumis still 1 asnumofmyfuncis local to it and different from global variablenum.print(num)— This line prints the value of the global variablenum, which is still 1.
Answered By
3 Likes