String is immutable data type String replace So why there is command for string to replace the values

0 votes
We cant change the values of Immutable data type.
Mar 28, 2020 in Python by Nelson
• 120 points
5,126 views

1 answer to this question.

0 votes

Hey, @Nelson,

replace() actually returns a *copy* of the argument string with relevant parts replaced. The original string is left intact. Strings are immutable in Python.

 t1="xyz" 

t2=t1.replace("x", "X") 

print(t1) #xyz

print(t2) #Xyz 

As you can see, the replace method doesn't change the value of the string t1 itself. It just returns a new string that can be used for other purposes.

I hope this will clear your doubt.

answered Mar 30, 2020 by Gitika
• 65,910 points

Related Questions In Python

0 votes
1 answer

How can I change the data type to string in Python?

You can use str(variablename) This is called conversion ...READ MORE

answered Dec 18, 2018 in Python by Shuvodip
698 views
+1 vote
1 answer
0 votes
1 answer

is there a way to send sql query data from redshift and send the data via email to sns?

I resolved this issue using AWS Glue ...READ MORE

answered Nov 21, 2020 in Python by Ruben
• 180 points
1,176 views
+1 vote
1 answer

What is the correct order to learn concepts in Python for machine learning?

Machine Learning is a vast domain. It ...READ MORE

answered Jul 25, 2018 in Python by Abhi
• 3,720 points
782 views
0 votes
1 answer

Is there anyway to obtain the full abstract from a 'PUBmed' article using bioPython

Hey Charlie, it's certainly possible to pull ...READ MORE

answered Aug 24, 2018 in Python by aryya
• 7,450 points
3,024 views
0 votes
1 answer

What's the canonical way to check for type in Python?

To check if o is an instance ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 58,090 points
679 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,146 views
0 votes
1 answer

How to check the value is double in the existing data that when ever the values are double print thats value

Hey, @There, I guess regarding your query you ...READ MORE

answered Nov 3, 2020 in Python by Gitika
• 65,910 points
668 views
0 votes
1 answer

How to create a unicode string in python with the string eg: This is a string?

Hey, @Roshni, It is very simple to execute, ...READ MORE

answered Jun 23, 2020 in Python by Gitika
• 65,910 points
514 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