在这段小代码中:
print('Your cards are:')
for i in playerCards:
print(i)
产生我想要的输出:
Your cards are:
TD
6D
但是,我想避免数组上每次迭代之间的行跳转。我怎样才能生产这个呢?
Your cards are: TD 6D
最佳答案
您可以指定 end
关键字参数来打印空格而不是换行符:
print('Your cards are:', end=' ')
for i in playerCards:
print(i, end=' ')
或者,仅使用一个带有参数解包的 print
函数调用:
print('Your cards are:', *playerCards)
关于python - 避免数组迭代中的跳行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27652229/