python replace chars in string code example
Example 1: python replace all occurrences in string
>>> 'no one knows how'.replace('no', 'yes')
'yes one kyesws how'
Example 2: python replace char in string
string = "geeks for geeks geeks geeks geeks"
print(string.replace("geeks", "Geeks"))
print(string.replace("geeks", "GeeksforGeeks", 3))
Example 3: replace character in string python
>>> x = 'xpple bxnxnx cherry'
>>> a = x.replace(x,a)
'apple banana cherry'
>>> first_a = x.replace(x,a,1)
'apple bxnxnx cherry'