Python - concatenate a string to itself, multiple times -


i want join strings my_string = "i good." such should printing same my_string 3 times, in my_string*3 space in between each full sentence. how do it? str.join(' ',my_string*3)?

i know basic question, want know this.

thank in advance, sammed

you're pretty close. try this:

>>> my_string = "i good." >>> " ".join([my_string]*3) 'i good. good. good.' 

you need [my_string]*3 instead of my_string*3 because want list containing string 3 times (that can joined) instead of having single big string containing message 3 times.

also, " ".join(a) shorthand str.join(" ", a).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -