Python Forum
Hi , why can't i return this value?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hi , why can't i return this value?
#1
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 !
Reply
#2
def my_sum(x, y):
       sum = x + y
       return sum
 
print(my_sum(1, 2))
Reply
#3
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.
Reply
#4
You can also assign it to a variable name.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020