/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
## Every object in Python has an identity, a type, and a value. The identity points to the object's location in memory. The type describes the representation of the object to Python. The value of the object is simply the data stored inside. ## The following example shows how to access the identity, type, and value of an object programmatically using the id(object), type(object), and variable name, respectively: >>> l = [1,2,3] >>> print id(l) 9267480 >>> print type(l) <type 'list'> >>> print l [1, 2, 3] ## After an object is created, the identity and type cannot be changed. If the value can be changed, it is considered a mutable object; if the value cannot be changed, it is considered an immutable object. ## Some objects may also have attributes and methods. ## Attributes are values associated with the object. Methods are callable functions that perform an operation on the object. ## Attributes and methods of an object can be accessed using the following dot '.' syntax: >>> class test(object): ... def printNum(self): ... print self.num ... >>> t = test() >>> t.num = 4 >>> t.printNum() 4