Advertisements
Advertisements
Question
Predict the output of the given code snippet.
ptr=50
def result():
global ptr
ptr=ptr+1
print ptr
result()
print ptrVery Short Answer
Advertisements
Solution
Trace:
- Initially, global
ptris50. - The first
print(ptr)displays50. global ptrallowsresult()to modify the global variable.result()increasesptrto51.
50
51
shaalaa.com
Is there an error in this question or solution?
Chapter 3: Classes in Python - EXERCISE [Page 63]
