How to insert a string into given string after specific word in Python

1 Answer

0 votes
s = 'python java c++'

word = 'java'

index = s.find(word) + len(word )

s = s[:index] + ' c' + s[index:]

print(s)

 
 
 
'''
run:
 
python java c c++

'''

 



answered Aug 31, 2021 by avibootz

Related questions

1 answer 150 views
2 answers 177 views
1 answer 197 views
1 answer 307 views
1 answer 137 views
1 answer 126 views
...