- Python Objects
- Internal Types
- Standard Types
- Object Identity Comparison
-
Boolean
- Standard Type Operators
- Object Value Comparison
- Object Attributes
- Other Built-In Types
- Standard Type Built-In Functions
- Type Factory Functions
- Categorizing the Standard Types
- Unsupported Types
- - 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
- TYPES
type([]) <type 'list'>
type({}) <type 'dict'>
type (' ') <type 'str'>
type(0) <type 'int'>
.......example
f = ()
type(f)
<type 'tuple'>
- Functions
- Methods
- 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)
- 2 == 2
2.46 <= 8.33
5+4j >= 2-3j
'abc' == 'xyz'
3 < 4 < 7
- foo1 = foo2 = 4.3
foo1 = 4.3 (foo2 = foo1)
foo1 = 4.3 (foo2 = 1.3 + 3.0) (foo1 is not foo2)
- and, or not
x, y = 3.1, -1024
- cmp() (Compares) a,b = -4, 12 (cmp(a,b)
repr()
str()
type() type(4) type(type(4))
(' ') (Back quote operator)
type() and isinstance()
- 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()
- dict()
bool()
set(), frozenset()
object()
classmethod()
staticmethod()
super()
property()
file()
- 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