I am kinda new to Python, and I would like to ask a question :
def spam(a):
a = 1 + a
return a
spam(21)
print(spam)
input()
After running it, the output is function spam at 0x021B24F8. Shouldn't the output be 22? Any help will be appreciated.
1 Answer 1
The problem is that your function, i.e. spam is returning a value. You need to accept the value returned by the function and store it in a different variable as in
s = spam(21)
print(s)
Here, you will store the returning value in the variable s which you will print it out.
After making the correction, the program will print as expected as in
22
Note - As mentioned, having a single statement print(spam(21)) also works as spam(21) will return 22 to the print function which will then print out the value for you!
2 Comments
print(spam(21)).