0. Description
It's not too much to say that objects are the most important part of an object-oriented programming language, and without an "object", object-oriented will be impossible to talk about. Python is also the case, if you can't master the object, you can hardly have great progress and ascension.
1.Python objects
(1) Object properties
Python uses the object model to store data, constructs any type of value as an object, and all Python objects have the following three attributes:
-
identity : A unique identity for each object, you can use the built-in function ID () to view the value (this value can be considered to be the intrinsic address of the object)
-
type : The type of the object determines the object (what type of value can be saved,what kind of action to follow, and what kind of rules), you can use the built-in function type () to view (the object's type is also an object, so type () returns an object, Instead of a string)
-
value : The data item represented by the object
For the identity attribute, it is readable; for type attributes, new types and classes can be modified, but not recommended for beginners, and Python has a series of Basic (built-in) data types that can be defined by itself (it is generally recommended to store specific data by creating and instantiating classes) ; For a value, depending on whether the object supports update operations.
(2) Object properties
Python uses the period notation to access properties, the most commonly used properties are functions and methods, and of course some Python objects have data properties.
2. Standard type
-
Number (divided into subtypes, with three integers)
integer int
long integer Long integer
Span style= "Color:rgb (192,0,0);" >floating Point Real number float
complex Number plural
-
string string
-
LIST    list
-
tuple tuples
-
It is important to note that the values constructed using the above basic types are the corresponding objects for that type.
3. Other built-in types
(1) Type object and type Object
As mentioned earlier, an object has a series of behaviors and attributes that are stored in the object's type:
>>> type <type ' int ' >
Type () returns a type object that indicates that 42 is a numeric type object, and that <type ' int ' > itself has a type that can continue to be viewed using type ():
>>> type <type ' type ' >
<type ' type ' > indicates that <type ' int ' > is a type object, and attempts to continue using the built-in function type () for further operation:
>>> type (type) <type ' type ' >
The result is a type object, so you can get the following conclusion:
-
All types of object types are type, which is also the default meta-Class (Metaclass) for all Python type roots and all Python standard classes
-
In Python, a class is a type, an instance is an object of the corresponding type (example of an analogy 42, 42 is a numeric type, it is a numeric object after a numeric type constructs a value)
(2) Null object for None:python
Python has a special type, called a null object or Nonetype, and it has only one value, which is None
>>> none>>> Type (None) <type ' Nonetype ' >
None has a useful property, and its Boolean value is always false.
(3) Boolean value
Before mentioning Boolean values, there are several points to note:
-
Each object inherently has a Boolean true or False value
-
Any number that has a null object value of zero or a Boolean value of a null object is False
-
A user-created class instance whose Boolean value is False if nonzero (__nonzero__ ()) or length (__len__ ()) is defined and the value is 0
4. Internal type
-
Code
-
Frame
-
Tracking Records
-
Slice
-
Omitted
-
Xrange
(1) Code object
The code object is a compiled Python source snippet, which is an executable object that can be obtained by calling the built-in function compile () and can then be executed by an EXEC command or an eval () built-in function.
The code object itself does not contain any execution environment information, which is the core of a user-defined function that dynamically obtains context when executed (in fact, the code object is a property of the function). In addition to the code object properties, a function has some properties that must be included in the function name document string default parameters and global namespaces.
(2) Frame object
The frame object represents the execution stack frame of the python. The Frame object contains all the information that the Python interpreter needs to know at run time, and its properties contain the following information:
-
Link to Previous Frame
-
Code object that is being executed
-
Local and global namespace dictionaries and current directives, etc.
Each time a function call produces a new frame, each frame object creates a C-stack frame that is used to track the Record object one place in the frame object.
(3) Tracking 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.
(4) Slicing object
Tile objects are created when you use the slice syntax for Python extensions.
(5) Omitting objects
The ellipsis object is used in the extended slice syntax to mark the function. This object represents an ellipsis in the slice syntax. Similar to the null object none, the ellipsis object has a unique name ellipsis:
>>> ellipsisellipsis>>> Type (ellipsis) <type ' ellipsis ' >
Its Boolean value is always true.
(6) Xrange Object
Calling the built-in function xrange () generates a Xrange object, and Xrange () is the sibling version of the built-in function range () for large datasets that need to save memory usage or range ().
This article is from the "fragrant fluttering leaves" blog, please make sure to keep this source http://xpleaf.blog.51cto.com/9315560/1750361
Python review and Collation 2:python objects