Python – Triple quote String concatenation
Sometimes, while working with Python Strings, we can have problem in which we need to perform concatenation of Strings which are constructed by Triple quotes. This happens in cases we have multiline strings. This can have applications in many domains. Lets discuss certain way in which this task can be performed.
Input : test_str1 = """mango is""" test_str2 = """good for health """ Output : mango good is for health Input : test_str1 = """Gold is""" test_str2 = """important for economy """ Output : Gold important is for economy
Method : Using
splitlines() + strip() + join()
The combination of above functions can be used to perform this task. In this, we perform the ask of line splitting using
splitlines(). The task of concatenation is done using
The original string 1 is : gfg is The original string 2 is : best for geeks String after concatenation : gfg best is for geeks