Python Forum
How to give space when concaneting strings
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to give space when concaneting strings
#1
>>> 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'
>>>
Reply
#2
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'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand strings and lists of strings Konstantin23 2 699 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 1,704 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  from global space to local space Skaperen 4 2,270 Sep-08-2020, 04:59 PM
Last Post: Skaperen
  Finding multiple strings between the two same strings Slither 1 2,482 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  How to remove space between strings sunnyarora 2 2,674 May-03-2019, 11:44 AM
Last Post: perfringo
  lists, strings, and byte strings Skaperen 2 4,183 Mar-02-2018, 02:12 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020