Skip to content
Advertisement

Add a space between string after multiplying the original ones

I have multiplied the original string and I want to add a space between them. How can I achieve it?

my_str = 'Data Science'
print(my_str * 3)

Output:

Data ScienceData ScienceData Science

Advertisement

Answer

Try join

my_str = 'Data Science'
' '.join([my_str]*3)  # -> 'Data Science Data Science Data Science'
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement