Python Forum

Full Version: How to give space when concaneting strings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
>>> str='Python is a great programming language'
>>> str
'Python is a great programming language'
>>> str1=str[0:11]
>>> str2=str[12:29]
>>> str3=str[30:39]
>>> newstr = str1 + str2 + str3
>>> newstr
'Python is agreat programminglanguage'
>>>
You could explicitly insert strings (either with concatenation or with f-strings), or you could join() the strings with a space.

>>> s1 + " " + s2 + " " + s3      #1a
'Python is a great programming language'
>>> f"{s1} {s2} {s3}"             #1b
'Python is a great programming language'
>>> " ".join((s1, s2, s3))        #2
'Python is a great programming language'