0

I'm still quite new to programming and I've been trying to figure out how to create a function that returns (in this case) three elements like strings and print them out in separate lines. For example:

tuple = ("name", "name", "name")

should end up looking like this:

name

name

name

Don't know if it makes sense? I know how to do it with an ordinary for loop, but can't figure it out with a function.

Nishant
  • 20,354
  • 18
  • 69
  • 101
Psmacks
  • 5
  • 3
  • 1
    What should the function's input/output? If you want to take a tuple and print it, make the tuple as an argument and write that loop inside the function. – Nishant Dec 25 '20 at 06:59

2 Answers2

0

You could just iterate the tuple in your function, e.g.

tuple = ("name", "name", "name")
for t in tuple:
    print(t)
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

You can use "\n\n" to concatenate strings in your function, like:

def print_strings(t):
    res = "\n\n".join(t)
    return res
test_values = ("name", "name", "name")
result = print_strings(test_values)
print(result)

By the way, keywords(like tuple) should not be used to declare variables, otherwise that keyword will lose its original function

keria
  • 46
  • 2