Home > Backend Development > Python Tutorial > Can strings be changed in Python3?

Can strings be changed in Python3?

高洛峰
Release: 2017-03-08 09:44:58
Original
1882 people have browsed it

Can strings be changed in Python 3?

There is a method for changing strings: replace, for example:

a = 'lkjhgfdsa'
a.replace('l','123')'
123kjhgfdsa' #返回结果
Copy after login

As can be seen from the above example, str can also be changed. but! ! !

This change does not really change the original string, but is equivalent to creating a new string:

>>> a = 'lkjhgfdsa'
>>> b = a.replace('l','123')
>>> a
'lkjhgfdsa'
>>> b
'123kjhgfdsa'
Copy after login

From the above example, the value of a has not been changed. We copy the "modified" string to b. It can be seen that a and b are completely different.

Summary: Strings cannot be changed in Python 3. If you use the str.replace method to change a string, the original string will remain unchanged and a new changed string will be created.

For more related articles, can strings be changed in Python3, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template