How to remove the first occurrence of a word from a string in Python

1 Answer

0 votes
string = "c c++ python java python php"

word = 'python'

string = string.replace(word + ' ', "", 1)

print(string)




'''
run:

c c++ java python php

'''

 



answered Apr 16, 2022 by avibootz
...