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
480 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,870 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 17, 2018 in Python by Shuvodip
143 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
135 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
257 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 23, 2018 in Python by aryya
• 7,420 points
1,423 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,100 points
150 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,100 points
7,653 views
0 votes
1 answer
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,870 points
106 views