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.
old value:  The value that we want to replace.

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.

  1. a="my name is java"
  2. b=" she is a very talented person"
  3. c="They have no knowledge in python"
  4. a=a.replace("java","python")
  5. b=b.replace("talented person","brave girl")
  6. c=c.replace("no","more",3)
  7. print(a)
  8. print(b)
  9. 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 



Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu