- char (Not for single or 8 bit)
- pointer (Python manages memory for you)
- int versus short versus long (Use plain integers)
- float versus double (single precision not supported) - use decimal float
IDENTITY
list = [1,2,3]
id(list[0])
30796824L
Identity : id () BIF
Type: type() BIF
Value: Data Item
Data Attributes
Classes, Class Instances,
Modules, Complex Numbers and files
Numbers (var1 = 10)
====================================================
- Type int(x)to convert x to a plain integer.
- Type long(x) to convert x to a long integer. ex. long(var1)
- Type float(x) to convert x to a floating-point number.
- Type complex(x) to convert x to a complex number with real part x and imaginary part zero.
- Type complex(x, y) to convert x and y to a complex number with real part x and imaginary part y. x and y are numeric expressions
====================================================
Integers
Boolean
Long Integer
Floating Points
Complex Number
String
List
Tuple
Dictionary
- Type >>>type(42)
- Null Object (None) x = None (Set Boolean to False)
- File
- Set/Frozenset ex cities = set(("Paris", "Lyon", "London","Berlin","Paris","Birmingham"))
- Function/Method
- Module
- Class
- Code Objects- Byte Compiled. ex:Create an Object as follow: compile('sum([1, 2, 3])', '', 'single') or
exec compile('sum([1, 2, 3])', '', 'single')
or to obtain a function's code object:
def f(s): print s and fenter a new line and then type: f.__code__
- Frame Objects
- Traceback Objects
- Slice Objects Create: sl = slice(0,4) ... Use: s = "ABCDEFGHIJKL" followed by sl = slice(0,4) and then print out: print s[sl]
- Ellipsis
- Xrange xrange() ex: for i in xrange(10):
... print(i)
Reduce the number of function calls
Only have one call made to type() function:
>>> import types
>>> if type (num) == types.IntType...
Object Value Comparison vs Object Identity Comparison
To be optimal:
if type(num) is types.IntType... # or type(0)
(Bypass Object Value Comparison if the objects are the same)
Reduce The number of Lookups
(Shortcut to find IntType by using from-import)
from types import IntType
if type(num) is IntType...
Convenience and Style - use isinstance
The Boolean function takes an object and a Type Object
to return True if the object in question is an instance of
one of the type objects
Table 4.5
Factory Producing a Good
int(), long(), float(), complex()
str(), unicode(), basestring()
list(), tuple()
type()
Storage Model
(How many objects can be stored in an object of this type)
Single Types - atomic or scalar storage
Multiple Objects - Container Storage (Compound/Composite)
Table 4.6
Update Model
Once created can object be changed?
Mutable - Can change object value
Immutable - Can not change value
Table 4.7
Table 4.8
Table 4.9 (Categorize Standard Types)
Storage - Update - Access
ex "What is the difference between lists and tuples? (Update model different)
Access Model
How do we access the values of the stored data?
- Direct
- Sequence
- Mapping