python中变量相乘时如何添加空格

2023-11-30

这是我的代码

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)

我想在每次单词相乘之间添加一个空格。那可能吗?


Use str.join在字符串序列之间放置空格:

print(' '.join([x] * c))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

python中变量相乘时如何添加空格 的相关文章

随机推荐