How to use string replace in python 3 x

0 votes
The string.replace() is deprecated on python 3.x. What is the new way of doing this?
Feb 18, 2022 in Python by Dev
• 6,000 points
468 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

String.replace can be used in the following ways:

For Example:

val = 'This is a Cat'
print(val.replace('Cat','Dog'))

Output

This is a Dog
val = 'This is a Cat and this is a Dog and this is a Rat'
print(val.replace('this','here',3 ))

Output

This is a Cat and here is a Dog and here is a Rat

In the second case along with replace(old, new, step) is also mentioned. This indicates how many times I want the particular string to be replaced.
Also, Python is case sensitive, hence the initial This is not changed to here.
Hope this helps.

answered Feb 18, 2022 by Nandini
• 5,480 points

edited Mar 5

Related Questions In Python

0 votes
1 answer

How to use string.replace() in python 3.x

replace() is a method of <class 'str'> ...READ MORE

answered Aug 3, 2018 in Python by Priyaj
• 58,020 points
1,374 views
+1 vote
2 answers

How to print first character of each word in upper case of a string in Python

text = "this is a sample python ...READ MORE

answered Jun 22, 2022 in Python by anonymous

edited Mar 5 12,705 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by aryya
• 7,460 points
1,560 views
0 votes
2 answers

How to use threading in Python?

 Thread is the smallest unit of processing that ...READ MORE

answered Apr 6, 2019 in Python by anonymous
1,522 views
0 votes
1 answer

How to use “raise” keyword in Python

You can use it to raise errors ...READ MORE

answered Jul 30, 2018 in Python by Priyaj
• 58,020 points
887 views
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 5, 2018 in Python by Omkar
• 69,220 points

edited Aug 8, 2018 by Omkar 8,383 views
0 votes
1 answer

TypeError: a bytes-like object is required, not 'str' when writing to a file in Python3

After what I observed, you would have ...READ MORE

answered Feb 11, 2022 in Python by Rahul
• 9,680 points
2,108 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,020 points
1,797 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,020 points
936 views
0 votes
1 answer

“stub” __objclass__ in a Python class how to implement it?

You want to avoid interfering with this ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 58,020 points
2,540 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP