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
13 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 themyfunc
function. Insidemyfunc
function,num = 10
defines a local variablenum
and assigns it the value of10
which is then returned by the function. It is important to note that the value of global variablenum
is still 1 asnum
ofmyfunc
is 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
2 Likes