![](/img/trans.png)
[英]How to prevent parentheses and quotation marks from being printed when printing a string with dictionaries/lists?
[英]How do I prevent the parens and quotations being printed when printing elements from a list?
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!') 。 我如何打印綠色和紅色贏得了比賽! 反而? 基本上,我想在沒有額外括號和引號的情況下打印列表中的元素,在句子中使用它們時。
返回格式化的字符串,而不是元組:
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!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.