joining strings python code example
Example 1: python join list to string
list = ['Add', 'Grepper', 'Answer']
Inline
> joined = " ".join(list)
> Add Grepper Answer
Variable
> seperator = ", "
> joined = seperator.join(list)
> Add, Grepper, Answer
Example 2: combine two strings python
>>> orig_string = 'Hello'
>>> orig_string + ', world'
'Hello, world'
>>> orig_string
'Hello'
>>> full_sentence = orig_string + ', world'
>>> full_sentence
'Hello, world'
Example 3: how to join strings in python
str1 = "Help"
str2 = "developers!"
print(str1 + ' ' + str2)
Example 4: python join string with common string
def merge(s1, s2):
i = 0
while not s2.startswith(s1[i:]):
i += 1
return s1[:i] + s2