Home > Software engineering >  Insert line break on same position as in another string
Insert line break on same position as in another string

Time:08-27

I have two strings:

s1 = '''One scientist
        said'''  

s2 = 'One man said'

I need to put '\n' sign instead space in s2 after second word as in s1. Lika that:

s2 = '''One man 
        said'''

But how I can do it?

CodePudding user response:

Try this:

s2 = 'One man said'
x = s2.split()[:2] # First two words
y = s2.split()[2:] # After first two
text_to_add = '\n        ' # Change if you want
out = x   text_to_add   y
print(out)

CodePudding user response:

Try this solution, it's really simple

s2 = 'One man\n said'

  • Related