(iv) "Four talents" in Python (strings, lists, dictionaries, collections)

Source: Internet
Author: User

Foreplay: The data series in Python is divided into variable (mutable) and immutable (immutable) two

Immutable: string, int, float, tuple

Feature: The same object occupies only one memory address, regardless of how many variables refer to it, such as A=1,b=1

Because it is immutable, each time a new object must be created, the Python garbage collection mechanism will automatically clean up if no references point to it.

Variable: list, Dict

Features: The same object, each reference it will open a new address in memory to save it, but when we operate on his value, the memory address is not changed

Summary: Immutable data types in Python Once the value of the variable is changed, it is equivalent to re-establish an object, so the memory address will also change;

The value of variable data type variables can be changed without causing changes in memory addresses, but if the value is referenced by multiple variables, each variable will open an address

One, a string (string) 1, a slice of str

(iv) "Four talents" in Python (strings, lists, dictionaries, collections)

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.