Python string replace not working

0 votes

Hi. I am trying to replace some characters in python string but it is not working.

I am using this code:

name = abc000
name.replace(“000”,””)

It showed proper output in the python interpreter. Then I tried it in Pycharm by adding the following line

print(name)

but it is not working.

Apr 4, 2019 in Python by raj
16,449 views

1 answer to this question.

0 votes

The replace method doesn’t store the altered value in the same variable. You need to store it in another variable and print it.

name=abc000
new_name=name.replace(“000”,””)
print(name)

This should work.

To know more, It's recommended to join our Python Training in Chennai today.

answered Apr 4, 2019 by Tina

edited Oct 7, 2021 by Sarfaraz

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,090 points
867 views
0 votes
1 answer

How do I check if input string is a valid regular expression or not in Python?

Hi. Good question! Well, just like what ...READ MORE

answered Feb 12, 2019 in Python by Nymeria
• 3,560 points
10,780 views
0 votes
1 answer

Python - Ubuntu install for SQLAlchemy not working

You can try using the version directly ...READ MORE

answered May 14, 2019 in Python by SDeb
• 13,300 points
2,048 views
0 votes
1 answer

Python error "TypeError: string indices must be integers, not str"

Hey @Dipti email_s.append(email_1["email_address"]) This is the list on ...READ MORE

answered Jul 5, 2019 in Python by Jinu
22,690 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,058 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,477 views
+7 votes
8 answers

Difference for string comparison in Python: 'is' vs. ==

If we use "==" means both variables ...READ MORE

answered Sep 3, 2018 in Python by Parul Raheja
1,771 views
0 votes
1 answer

How to replace values with None in Pandas data frame in Python?

Actually in later versions of pandas this ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 58,090 points
11,180 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