在python中乘以变量时如何添加空格 [英] How to add a space when you're multiplying variables in python
本文介绍了在python中乘以变量时如何添加空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
print("Type in another set of words")
x = input()
print("Now type in how many times you want it to appear (WHOLE NUMBERS ONLY!)")
c = int(input())
print(x * c)
每次单词相乘时,我想在它们之间添加一个空格.这可能吗?
I want to add a space between every time the word is multiplied. Is that possible?
推荐答案
使用 str.join 在字符串序列之间放置一个空格:
Use str.join to place a space between a sequence of strings:
print(' '.join([x] * c))
这篇关于在python中乘以变量时如何添加空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文