replace function:
python having different types of in-built functions from them replace() is one of the function.- The replace() function name itself saying that "one string is replaced with the other string".
- It consists of three parameters old value, new value, and count.
new value: The value we want to replace with is the new value.
count: The number of times of the value we want to replace old with the new value.
Syntax: str.replace(old value,new value,count)
#write a python code to demonstrate replace function.
- a="my name is java"
- b=" she is a very talented person"
- c="They have no knowledge in python"
- a=a.replace("java","python")
- b=b.replace("talented person","brave girl")
- c=c.replace("no","more",3)
- print(a)
- print(b)
- print(c)
- In the above program in line 5, we want to replace no with more and we gave the count as 3 so in the string where we have no that will be replaced with more up to 3 times only.
- so the output will be as shown in below.
Output: my name is python
she is a very brave girl
They have more kmorewledge in python
No comments