-1

I wrote a function in Python which returns should simple string based on 3 parameters, but it returns a tuple instead of a string.

def my_TAs(test_first_TA, test_second_TA, test_third_TA):

    return test_first_TA, test_second_TA, "and", test_third_TA, "are awesome!."

test_first_TA = "Joshua"

test_second_TA = "Jackie"

test_third_TA = "Marguerite"

print(my_TAs(test_first_TA, test_second_TA, test_third_TA))

Output:

('Joshua', 'Jackie', 'and', 'Marguerite', 'are awesome!')

Desired output:

"Joshua, Jackie, and Marguerite are awesome!".
mkrieger1
  • 19,194
  • 5
  • 54
  • 65

2 Answers2

2

The reason for this is that in python, if you use , to separate some values, it is interpreted as a tuple. So when you return, you are returning a tuple, not a string. You could either join the tuple, or use format strings like below.

return f'{test_first_TA}, {test_second_TA}, and {test_third_TA} are awesome!'
rak1507
  • 392
  • 3
  • 6
0

You can do it using join

def my_TAs(test_first_TA, test_second_TA, test_third_TA):
    return test_first_TA, test_second_TA, "and", test_third_TA, "are awesome!."

test_first_TA = "Joshua"
test_second_TA = "Jackie"
test_third_TA = "Marguerite"

print(' '.join(my_TAs(test_first_TA, test_second_TA, test_third_TA)))