Xtense
Xtense

Reputation: 646

Returning output in multiple lines

I want to return the output in one line below the other instead of all in the same line for my code

def f(a,b):
  return a,b

f(2,3)

So rather than in tuple form I want to return an output like:

2
3

How can I do that

Upvotes: 0

Views: 1793

Answers (3)

Devansu Yadav
Devansu Yadav

Reputation: 51

Another way to do this

 def f(a, b):
   return a, b


 output = f(2, 3)
 print(str(output[0]) + "\n" + str(output[1]))

Upvotes: 0

Sibyl
Sibyl

Reputation: 145

You can use generator with yield

def f(a, b):
    yield a
    yield b


for x in f(2, 3):
    print(x)

Upvotes: 0

CMinusMinus
CMinusMinus

Reputation: 456

If you want to output the tuple, I would recommend

print(a)
print(b)

instead of a return. I don't know, why you would want it to return in different lines, but you could try

return a+"\n", b

Upvotes: 1

Related Questions