简体   繁体   English

(Python) 打印时分隔列表

[英](Python) Separating lists when printing

I am writing a code for school and we need to make a deck of cards as part of it.我正在为学校编写代码,我们需要制作一副卡片作为其中的一部分。 I have already made the deck but I do not know how to print it the way I want it.我已经制作了甲板,但我不知道如何按我想要的方式打印它。 It either prints with all the brackets and commas or none.它要么打印所有括号和逗号,要么不打印。 My goal is to print it with a comma separating every two values of the list.我的目标是用逗号分隔列表的每两个值来打印它。 Any suggestions?有什么建议么?

Here's way, maybe not the best result:这里的方式,也许不是最好的结果:

cards = ['3','A','7','Q','4']
print(f'"{", ".join(cards)}"')

Output: Output:

"3, A, 7, Q, 4"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM