Can strings in Python 3 be changed ?, Python string

Source: Internet
Author: User

Can strings in Python 3 be changed ?, Python string

Can strings in Python 3 be changed?

The string has changed this method: replace, for example:

A = 'lkjhgfdsa 'a. replace ('l', '000000') '123kjhgfdsa '# return results

From the above example, we can see that 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', '000000') >>> a 'lkjhgfdsa' >>> B '123kjhgfdsa'

As shown in the preceding example, the value of a is not changed. We copy the modified string to B. We can see that a and B are completely different.

Summary: strings in Python 3 cannot be changed. If the str. replace method is used to change the string, the original string remains unchanged and a new string is created after the change.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.