Python Forum

Full Version: How to print string multiple times separated by delimiter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
Is there any way to print single string multiple tiles in same line and separated by dilimiter:


print(*range(5), sep=", ") ## this is working
s = 'abcd'
print(s*2) ## this is working
print((s*2),sep=' and ') ## this is not working
It is not working because it is one string item
s = 'abcd'
print(*(s for _ in range(2)), sep=' and ')
Output:
abcd and abcd