Python Forum
Function - Return multiple values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function - Return multiple values
#7
(Jun-01-2021, 01:11 AM)tester_V Wrote: Thanks! I could return all the values by replacing 'return' with 'print'

No, you can't! All functions which don't have return or yield return None. Printing is not same as returning

>>> def my_func():
...     print('Hello world')
...
>>> print(my_func())
Hello world                    # what your function does
None                           # what your function returns
>>>
If you print from function then you give away flow control:

>>> value = my_func()         # I want to bind name to value returned by function
Hello world                   # as 'side-effect' it prints; there is no way to control it
>>> print(value)              # return value None is binded to name
None
tester_V likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Function - Return multiple values - by tester_V - May-31-2021, 11:14 PM
RE: Function - Return multiple values - by tester_V - Jun-01-2021, 01:11 AM
RE: Function - Return multiple values - by perfringo - Jun-01-2021, 08:23 AM
RE: Function - Return multiple values - by tester_V - Jun-01-2021, 01:38 AM
RE: Function - Return multiple values - by tester_V - Jun-01-2021, 06:39 AM
RE: Function - Return multiple values - by tester_V - Jun-01-2021, 05:14 PM
RE: Function - Return multiple values - by tester_V - Jun-02-2021, 05:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  __init__() got multiple values for argument 'schema' dawid294 4 2,743 Jan-03-2024, 09:42 AM
Last Post: buran
  Need to return 2 values from 1 DF that equals another DF cubangt 5 704 Oct-21-2023, 02:45 PM
Last Post: deanhystad
  nested function return MHGhonaim 2 675 Oct-02-2023, 09:21 AM
Last Post: deanhystad
  return next item each time a function is executed User3000 19 2,460 Aug-06-2023, 02:29 PM
Last Post: deanhystad
  function return boolean based on GPIO pin reading caslor 2 1,246 Feb-04-2023, 12:30 PM
Last Post: caslor
  Adding values with reduce() function from the list of tuples kinimod 10 2,802 Jan-24-2023, 08:22 AM
Last Post: perfringo
  [Solved]Return values from npyscreen Extra 2 1,218 Oct-09-2022, 07:19 PM
Last Post: Extra
  Parallelism with return values Plexian 7 1,580 Aug-14-2022, 09:33 AM
Last Post: Plexian
  How to combine multiple column values into 1? cubangt 15 3,041 Aug-11-2022, 08:25 PM
Last Post: cubangt
  function accepts infinite parameters and returns a graph with those values edencthompson 0 893 Jun-10-2022, 03:42 PM
Last Post: edencthompson

Forum Jump:

User Panel Messages

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