replace() Method

Replace Method

x.replace('','')

Example:

In [24]:
A = "WELCOME, let's learn new method "
In [25]:
# Replce WELCOME with Hello in A and put the result in B

B = A.replace('WELCOME', 'Hello')
In [26]:
# Print B
B
Out[26]:
"Hello, let's learn new method "

Example:

In [27]:
C = "WELCOME, let's learn 1 new method "
In [28]:
# Replce 1 with more than 1 in C and put the result in D

D = C.replace('1', 'more than 1')
In [29]:
# Print D

D
Out[29]:
"WELCOME, let's learn more than 1 new method "