Internal Data Types
A number of objects used by the interpreter are exposed to the user. These include trace back objects, code objects, frame objects, generator objects, slice objects, and the Ellipsis object. It is rarely necessary to manipulate these objects directly. However, their attributes are provided in the following sections for completeness.
1. Code
2. Frame
3. Trace back
4. Slice
5. Ellipse
6. Generator
Type Category |
Type Name |
Description |
Internal
|
types.CodeType |
Byte-compiled code |
types.FrameType |
Execution frame |
|
types.GeneratorType |
Generator object |
|
types.TracebackType |
Stacks traceback of an exception |
|
types.SliceType |
Generated by extended slices |
|
types.EllipsisType |
Used in extended slices |
Code Objects
Code objects represent raw byte-compiled executable code, or bytecode, and are typically returned by the built-in compile() function. Code objects are similar to functions except that they don’t contain any context related to the namespace in which the code was defined, nor do code objects store information about default argument values. A code object, c, has the following read-only attributes:
Frame Objects
Frame objects are used to represent execution frames and most frequently occur in traceback objects (described next). A frame object, f, has the following read-only attributes:
Traceback Objects
Traceback objects are created when an exception occurs and contains stack trace information. When an exception handler is entered, the stack trace can be retrieved using the sys.exc_info() function. The following read-only attributes are available in traceback objects:
Generator Objects
Generator objects are created when a generator function is invoked (see Chapter 6, "Functions and Functional Programming"). A generator function is defined whenever a function makes use of the special yield keyword. The generator object serves as both an iterator and a container for information about the generator function itself. The following attributes and methods are available:
Slice Objects
Slice objects are used to represent slices given in extended slice syntax, such as a[i:j:stride], a[i:j, n:m], or a[..., i:j]. Slice objects are also created using the built-in slice([i,] j [,stride]) function. The following read-only attributes are available:
Ellipsis Object
The Ellipsis object is used to indicate the presence of an ellipsis (...) in a slice. There is a single object of this type, accessed through the built-in name Ellipsis. It has no attributes and evaluates as True. None of Python’s built-in types makes use of Ellipsis, but it may be used in third-party applications.
Standard Type Built-in Functions
cmp(obj1,obj2)
type(obj)
repr(obj)
boolean operators
not
and
or
Categorizing the Standard Types
A type which holds a single object we will call it as literal\scalar storage and those which can hold multiple objects we will call it as container storage.
Container ------àcomposite\compound.
Storage model category |
python types |
Literal scalar |
Numbers, string |
Container |
Lists, tuples, dictionaries |
Update model changed
· Mutable objects are those whose values can be changed.
· Immutable objects are those values cannot be changed.
S.No. |
Data type |
Storage model |
Update model |
Access Model |
1 |
Numbers |
Literal \scalar |
Immutable |
direct |
2 |
string |
Literal \scalar |
Immutable |
sequence |
3 |
lists |
container |
mutable |
sequence |
4 |
tuples |
container |
Immutable |
sequence |
5 |
dictionaries |
container |
mutable |
mailing |