1
def winners(finish_order, teams):
    return finish_order[0], 'and', teams[finish_order[0]], 'won the race!'

print(winners(['Green', 'Zelda', 'Frog'], {'Zelda':'Midna', 'Frog':'Frogette', 'Green':'Red'}))

所以运行上面的代码会打印('Green', 'and', 'Red', 'won the race!')。我如何打印绿色和红色赢得了比赛!反而?基本上,当在句子中使用它们时,我想打印列表中的元素,而不需要额外的括号和引号。

4

1 回答 1

1

返回格式化字符串,而不是元组:

def winners(finish_order, teams):
    return '{} and {} won the race!'.format(finish_order[0], teams[finish_order[0]])

print(winners(['Green', 'Zelda', 'Frog'], {'Zelda':'Midna', 'Frog':'Frogette', 'Green':'Red'}))

印刷:

Green and Red won the race!
于 2020-09-28T10:19:24.993 回答