What is a Python object

Source: Internet
Author: User

python use the object model to store data, which means that a value of any type is constructed as an object. All python objects have three attributes: Identity ID, type, and value.

Identity ID : unique identity, you can use the built-in function ID () This value can be considered to be the memory address of the object. The comparison of object identities can be done by operator is or is not, to determine if they point to (reference) the same object, here is an interesting example:

>>> a = 1>>> b = 1>>> c = 1000>>> D = 1000>>> A is btrue>>> c is dFa Lse>>> ID (a), id (b), ID (c), id (d) (11258984, 11258984, 12386056, 11594792)

can be seen,aand thebpoint to the same object, butCand theDbut different, why is this? This is because the integer object and the string object are immutable objects,pythoncache them very efficiently, but the integer object caches only simple integers, as in the example above0, +Will not be cached.

Type: the type of an object determines what type of value the object can hold, what kind of action it can take, and what rules it can follow to use the built-in functiontype ()Viewpythontype of object, or you can use theisinstance (), inpythontypes are also object base data types include numbers, integers, booleans, long integers, floating-point, plural, string, list, tuple, and dictionary, and some other built-in types, which are types,None, files, collections, functions, modules, and classes, in addition to some internal types, i.e. code, frames, trace records, slices (step slices, multidimensional slices, omit slices), omitted (omitting an object has a unique nameellipsis),Xrange(isRange ()supplement).

value: The data item represented by the object. Comparison of object values you can also use the cmp () built-in function in addition to some common operators .

The types mentioned above can be categorized according to three different models: the storage model, the update model, and the access model.

There are two types of storage models-

Atomic type: Numeric, String.

Container type: list, tuple, dictionary.

There are two types of update models-

Mutable type: list, dictionary.

Immutable types: Numbers, strings, and tuples.

There are three types of access models-

Direct access: Numbers.

Sequential access: strings, lists, and tuples.

Map access: Dictionary.


What is a Python object

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.