-2

How can I change the format in which multiple return values from a function are displayed. When I print the function, the two return values are displayed inside parentheses. Is there a way to change this?

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

This prints the following: (2, 4)

I would like for it to be displayed like this: 2 and 4

Ch3steR
  • 20,090
  • 4
  • 28
  • 58
Lis
  • 1
  • 1
  • Does this answer your question? [How to specify return type of a function when returning multiple values?](https://stackoverflow.com/questions/59049760/how-to-specify-return-type-of-a-function-when-returning-multiple-values) – Sapt-Programmer Oct 09 '21 at 06:13
  • The thing is I am trying to format the way it is displayed when I print the actual function. Is there a way that I can format the way the return values are displayed when printing the function? – Lis Oct 09 '21 at 06:24
  • Your code does not "print the function", it prints the return value. Calling a function is an action, not a thing. – MisterMiyagi Oct 09 '21 at 06:48

1 Answers1

0

You can use string format:


def test():
    return 1, 2


print("%s and %s" % (test()))

Here and here you can read more about its functionalities.

marcel h
  • 742
  • 1
  • 7
  • 20