Python core Programming Notes Python Object

Source: Internet
Author: User
Tags stack trace

4th Python object 1, Python object

Python uses the object model to store data, and constructs any type of value as an object. All objects have three properties:

    • Identity, which can be viewed through the built-in function ID (), which is the memory address of the object.
    • Type, which can be viewed through the built-in function type ().
    • A value that represents the data item for the object.
>>> 12>>> id(p)31108092>>> ‘int‘>>>> p12>>> 
2. Standard type

Integer integer, long integer, float float, complex type complex number, Boolean bool, string, list, tuple tuple, dictionary dictionary.

3. Other built-in types
    • Type Object

      The type is itself an object, and its type is ' type '.

type(1)<type ‘int‘>type(type(1))<type ‘type‘>
    • Null object for None--python

      Python has a special type, called a null object or Nonetype, and it has only one value: The Boolean value of None,none is false.

    • File

    • Collection
    • Functions/Methods
    • Module
    • Class
4. Internal type

Internal type we generally do not pay too much attention and use, understand can.

    • Code Object

      The code object is a compiled Python source code fragment that can be executed. The code object can be obtained through the built-in function compile (). Code objects can be executed by the EXEC command or the built-in function eval ().

    • Frame

    • Tracking Record objects

      When a program exits abnormally, a trace record object containing stack trace information for the exception is created:

>>> pri   Traceback (most recent call last):    File"<stdin>"1in <module>   NameError:‘pri‘notdefined
    • Slice Object

      When you use the slice syntax of Python, a slice object is created.

    • Omit object

      Used in the slice syntax to mark the function. such as Str[::2].

    • Xrange Object

      Calling the built-in function, xrange (), generates a Xrange object, Xrange is the sibling version of range, which is used to save memory or a large dataset where range cannot be completed.

5. Standard type operator
    • Comparison of object values
    • Object Identity Comparison

      This relates to Python's "reference Counting" knowledge, which is summarized in the previous article. Python also provides an IS and is not operator to test whether two variables point to the same object.

>>> 1>>> b =a>>> 2>>> a == bTrue>>> is cFalse>>> isnot cTrue>>> is bTrue

We can also directly determine whether they point to the same object by ID or not:

id(a),id(b),id(c)(311082243110822431108212)
6. Standard type built-in function
    • CMP (OBJ1,OBJ2)

      Obj1 greater than OBJ2 returns 1, less than return-1, which is equal to return 0.

>>> 1,2,3,2>>> cmp(b,a),cmp(b,c),cmp(b,d)(1, -10)
    • Type (obj)
    • STR (), repr (), "operator

      The STR (), repr (), and "operators all have the ability to get the contents of an object as a string. The string obtained by STR () is good readability, and the string obtained by repr () can often be used to regain the object.

>>> str([1,2,3])‘[1, 2, 3]‘>>> repr([1,2,3])‘[1, 2, 3]‘>>> ‘[1,2,3]‘‘[1,2,3]‘
7. Type Factory function

The Python2.2 unifies classes and types. The so-called built-in type conversion functions like int (), type (), list () are all factory functions, which means they look like functions, essentially classes, and when they are called, they actually generate an instance of that type, like a factory-generated cargo.

8. Classification of standard types

Store the model, update the model, and access the model.

9. Types not supported by Python
    • Char or byte
    • Pointer
    • Integral type

      There is no int, short, long in python like the C language. When you use an integer value out of range, Python automatically returns a long integer to you, and Python's long integer represents a large range of values.

    • Float vs Double

      Python's floating-point type float is actually a double of c. The floating-point type is always imprecise, so Python also provides the decimals module, which has arbitrary precision and is useful when dealing with certain values such as money, decimals modules.

Original: http://blog.csdn.net/u012162613/article/details/44049607

Python core Programming Notes 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.