Python Forum
Hi , why can't i return this value? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Hi , why can't i return this value? (/thread-24326.html)



Hi , why can't i return this value? - Houston222 - Feb-09-2020

def my_sum(x, y):
       sum = x + y
       return sum

my_sum(1, 2)
Hi all , i am trying to call this function, but this function cannot return the result for some reason, my i know why ?

Many thanks !


RE: Hi , why can't i return this value? - michael1789 - Feb-09-2020

def my_sum(x, y):
       sum = x + y
       return sum
 
print(my_sum(1, 2))



RE: Hi , why can't i return this value? - ndc85430 - Feb-09-2020

Note that you need to do something with the return value, as shown above. The function is returning, but since you don't use the value, it's just discarded.


RE: Hi , why can't i return this value? - karkas - Feb-09-2020

You can also assign it to a variable name.