python - 在python中乘以变量时如何添加空格

标签 python printing

这是我的代码

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)

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

最佳答案

使用str.join在字符串序列之间放置一个空格:

print(' '.join([x] * c))

关于python - 在python中乘以变量时如何添加空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18938965/

相关文章:

python - Keras ANN 的 Pandas 数据框形状不正确

java - 如何在不显示 printdialog 的情况下在 java 中打印

c - OSX - 捕获打印作业。

c# - WinForms 打印到默认打印机,即使它不可用/连接

javascript - 使用 javascript 打印隐藏在屏幕上的部分

css - 谷歌浏览器和打印

python - 在 Python 中从 URL 下载视频

python - 机器人框架库动态导入不保持全局

python - 用 Python 调整终端大小?

python - 如何返回一个值,但继续执行