0

So i have a function that has to return 3 values, i haven't found a better way to do this other than returning a list. Is this code a good programming practice? And if not how to fix it.

Example function:

def func():
    #code
    return [a,b,c]

Main code:

   #code
   list = func()
   k = list[0]
   l = list[1]
   m = list[2]
Takis Pan
  • 35
  • 6

1 Answers1

1

You can pack/unpack directly in python:

def func():
    a = 1
    b = 2
    c = 3
    return a, b, c

k, l, m = func()
Paul H
  • 65,268
  • 20
  • 159
  • 136
  • to be pedantic, `a, b, c` just creates a tuple, rather than a list, it's not more direct. But definitely, OP should use unpacking. – juanpa.arrivillaga May 29 '20 at 07:06
  • @juanpa.arrivillaga if we're being pedantic, the OP is mostly concerned with the best way of returning multiple values and it's only a coincidence that they tried a list first. – Paul H May 29 '20 at 19:00