Q. What will be the output of following programs?
(i)
num = 1
def myfunc ():
return num
print(num)
print(myfunc())
print(num)
(ii)
num = 1
def myfunc():
num = 10
return num
print (num)
print(myfunc())
print(num)
(iii)
num = 1
def myfunc ():
global num
num = 10
return num
print (num)
print(myfunc())
print(num)
(iv)
def display():
print("Hello", end = ' ')
display()
print("there!")
Answer =
(i)
Output:-
1
1
1
>>>
(ii)
Output:-
1
10
1
(iii)
Output:-
1
10
10
(iv)
Output:-
Hello there!
Is the 2nd ans because of local scope variable ?
ReplyDeleteno clue
DeleteYes.
Deletei) is wrong
ReplyDeletef should not be capitalised
output:
1
1
1
can someone explain the 3rd one?
ReplyDeleteglobal num means it should be using 1 right? cause 1 is in global scope and 10 is in local scope? I don't understand why we are using local variable? Can someone explain
global num
DeleteChange value of num in whole program.
Can u explain i)
ReplyDeleteas it should be 1
None
1
Please copy it and run it in your python software.
DeleteI've never seen such an interactive and responsive website author..
ReplyDeleteThankyou so much : )
Deletecan u explain 4
ReplyDeleteDo you know about "end = ' ' " statement.
Deletethe first answer should be 1 10 1 because you have called the func in statement 2 nd i have tried it on editor
ReplyDeleteHi
ReplyDeleteYes..
DeleteIn 1) it should be
ReplyDelete1
None
1
You are wrong because myfunc is returning num.
DeleteI dont understand
ReplyDeleteWhich one : )
Deleteall of it!
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )