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 in Python by raj
541 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.

answered Apr 4 by Tina

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
• 56,940 points
95 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 in Python by Nymeria
• 3,520 points
136 views
0 votes
1 answer

Python - Ubuntu install for SQLAlchemy not working

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

answered May 14 in Python by SDeb
• 13,190 points
105 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 in Python by Jinu
2,476 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 349 views
+4 votes
6 answers
+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
489 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
• 56,940 points
2,116 views