Python core Programming Note----Python object

Source: Internet
Author: User
Tags stack trace

The contents of this chapter:

Python Object

Built-in type

Standard type operator

Comparison of values

Object Identity Comparison

Boolean type

Standard type built-in functions

Standard type Overview

Various types

Unsupported types

Python Object

All Python objects have three properties: identity, type, and value

Identity: The unique identity, the memory address of the object, and the built-in function ID () can be obtained. (rarely used) Read-only

Type: The type of the object determines what type of value the object can hold, what operations can be done, and what rules to follow. The built-in function type () looks at the type of the object, because the type is also an object in Python, so type () returns an object instead of a simple string. Read-only

Value: The data item represented by the object

Object properties: Python uses the period (.) notation to access the property. The most commonly used properties are functions and methods, and some Python types have data attributes, including: Classes, class instances, modules, complex numbers, and files

Standard type

Digital

Integer integer type

Boolean Boolean type

Long integer length int

Floathing Point Real number float type

Complex number plural type

String strings

List lists

Tuple tuples

Dictionary Dictionary

Other built-in types:

Type

Null object

File

Set/fixed Set

Functions/Methods

Module

Class

Type Object and type Object

>>> type ($)

<type ' int ' >

>>> type ("type")

<type ' type ' > Types of all types of objects are type default meta-class

None------NULL object for Python

A null object or Nonetype has only one value of none, and it does not support any operations or any built-in methods. None has a useful property, and its Boolean value is always False

The Boolean value of the object is False:none False for all values of zero 0 (integer) 0.0 (floating-point) 0L (Long Integer) 0.0+0.0j (plural) "" (empty string) [] (Empty list) (empty tuple) {} (empty dictionary)

Internal type

Code, frame, track record, slice, omit, Xrange

Code object:

The code object is a compiled Python source snippet, which is an executable object. The code object can be obtained by calling the built-in function compile (). Code objects can be executed by the EXEC command or the eval () built-in function
A code object is a property of a function

Frame object:

The Frame object represents the execution stack frame of the python. Each time a function call produces a frame, each frame object creates a C-stack frame accordingly. One place to use the frame object is to track the Record object

Trace Record object:

When an exception occurs, a trace record object that contains the stack trace information for the exception is created. If an exception has its own handler, the handler can access the trace Record object.

Slice object:

Tile objects are created when you use the slice syntax for Python extensions.

The slice syntax allows for different index slice operations, including step slices, multidimensional slices, and omitted slices.

Multidimensional slice syntax: Sequence[start1:end1,start2:end2] or using omit sequence[...,start1:end1], or it can be generated by the slice () of the built-in function

Step slice: sequence[start index: End index: Step value]

>>> foostr = ' ABCDE '

>>> Foostr[::-1]

' EDCBA '

>>> Foostr[::-2]

' ECA '

>>> foolist = [123, ' Xba ', 342.23, ' abc ']

>>> Foolist[::-1]

[' abc ', 342.23, ' XBA ', 123]

Omit object:

Xrange object:

Calling the built-in function xrange () generates a Xrange object. is the brother version of range for large datasets that need to save memory usage or range () from being completed.

Standard type operator

Comparison of object values

>>> 2 = = 2

True

>>> 2.46 <= 8.33

True

>>> ' abc ' = = ' xyz '

False

>>> 3 < 4 < 7

True

>>> 4 > 3 = = 3

True

>>> 4 < 3 < 5! = 2 < 7

False

The comparison operation is the numeric value of the object being compared, not the object itself

Standard type value comparison operators:

Expr1 < expr2; expr1 less than EXPR2

Expr1 > expr2; expr1 greater than EXPR2

Expr1 <= expr2; expr1 less than equals expr2

Expr1 >= expr2; expr1 greater than equals EXPR2

Expr1 = = expr2; Expr1 equals EXPR2

Expr1! = EXPR2; expr1 Not equal to EXPR2

Expr1 <> expr2 expr1 not equal to EXPR2

object identity comparison:  
    objects can be assigned to another variable, because each variable points to the same data object, and as long as any one of the references changes, the other references to that object change with    
    foo1 and Foo2 point to the same object     

foo1 = Foo2 = 4.3

foo1 = 4.3

Foo2 = Foo1

foo1 and Foo2 point to different objects

foo1 = 4.3

Foo2 = 1.3 + 3.0

test whether two variables point to the same object:

A is B

ID (a) = = ID (b)

>>> a = [5, ' hat ',-9.3]

>>> B = A

>>> A is B

True

>>> A is not B

False

>>> B = 2.5e-5

>>> b

2.5e-05

>>> A

[5, ' hat ',-9.3]

>>> A is B

False

>>> A is not B

True

Standard type Object Identity comparison operator

Obj1 is obj2; Obj1 and Obj2 are the same object

Obj1 is not obj2; Obj1 and obj2 are not the same object

Boolean type

Standard type Boolean operator

Not expr, the logic of expr

Expr1 and EXPR2; the logic of Expr1 and EXPR2

Expr1 or EXPR2; Expr1 and expr2 logic or

Standard type built-in functions

CMP (OBJ1,OBJ2) compares Obj1 and Obj2, and returns integer I based on the results of the comparison:

I < 0 if obj1 < obj2

I > 0 if obj1 > obj2

i = = 0 if obj1 = = Obj2

Repr (obj) or ' obj ' returns a string representation of an object

STR (obj) returns an object that fits into a well-readable string representation

Type (obj) to get an object of the kind and return the corresponding type object type


Storage Model Classification:

Scalar/atomic Type numeric value, string

Container type list, tuple, dictionary


To update the model:

mutable Type list, dictionary

Immutable type number, string, tuple


Type of Access

Direct access to numbers

Sequential access to strings, lists, tuples

Map Access Dictionaries



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