问题
Here is my code
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?
回答1:
Use str.join to place a space between a sequence of strings:
print(' '.join([x] * c))
回答2:
You can use string formatting:
print('{} '.format(x)*c)
来源:https://stackoverflow.com/questions/18938965/how-to-add-a-space-when-youre-multiplying-variables-in-python