KnowledgeBoat Logo

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