Computer Science
What will be the output of following program ?
num = 1
def myfunc():
return num
print(num)
print(myfunc())
print(num)
Python
Python Functions
6 Likes
Answer
1
1
1
Working
The code initializes a global variable num
with 1. myfunc
just returns this global variable. Hence, all the three print
statements print 1.
Answered By
2 Likes
Related Questions
What will the following function return ?
def addEm(x, y, z): print(x + y + z)
What will the following function print when called ?
def addEm(x, y, z): return x + y + z print(x + y + z)
What will be the output of following program ?
num = 1 def myfunc(): num = 10 return num print(num) print(myfunc()) print(num)
What will be the output of following program ?
num = 1 def myfunc(): global num num = 10 return num print(num) print(myfunc()) print(num)