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 in Python by Nelson
• 120 points
151 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 by Gitika
• 36,850 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
104 views
+1 vote
1 answer
0 votes
0 answers

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

is there a way to  send sql ...READ MORE

Aug 28 in Python by Ruben
• 120 points
32 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,680 points
190 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,380 points
1,028 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
• 57,640 points
106 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
• 57,640 points
6,321 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 in Python by Gitika
• 36,850 points
57 views
0 votes
1 answer

How to remove the white spaces from the string “aaa bbb ccc ddd eee”?

Hi, @Roshni, You can do it Using join, read ...READ MORE

answered Jun 26 in Python by Gitika
• 36,850 points
75 views