Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add a string to a multiline string in python without creating new line

I have two strings. One of them is a normal string and the other one is multiline.

a = '1'
b = """
abc
xyz
"""

This is the output that I want:

1- abc
xyz

I have tried to use a f-string:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

result = f'{a}- {b}'

But it creates a new line at the beginning which I don’t want.

>Solution :

Because you have \n in the beginning of the string.

a = '1'
b = """
abc
xyz
"""

Remove that

b = """abc
xyz
"""
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading