inserting into a string python code example
Example 1: python merge list into string
>>> sentence = ['this','is','a','sentence']
>>> '-'.join(sentence)
'this-is-a-sentence'
Example 2: how to append string to another string in python
var1 = "foo"
var2 = "bar"
var3 = f"{var1}{var2}"
print(var3) # prints foobar
Example 3: insert into string python
def insert (source_str, insert_str, pos):
return source_str[:pos]+insert_str+source_str[pos:]
Example 4: insert into string python
>>> line = 'Kong Panda'
>>> index = line.find('Panda')
>>> output_line = line[:index] + 'Fu ' + line[index:]
>>> output_line
'Kong Fu Panda'