Chapter 4


1.

Python objects

All Python objects have three attributes: type, ID, and value. All are read-only with a possible exception of the value (which can be changed only if the object is mutable).

5.

str() vs. repr()

repr() is a built-in function while str() was a built-in function that changed to a factory function in Python 2.2. They will both return a string representation of an object; however, str() returns a printable string representation while repr() (and the backquote operator '') return an evaluatable string representation of an object, meaning that it is a string that represents a (valid) Python object that would be created if passed to eval().

6.

Object equality

type(a) == type(b)

whether the value of type(a) is the same as the value of type(b)... == is a value compare

type(a) is type(b)

whether the type objects returned by type(a) and type(b) are the same object


Since there exists only one (type) object for each built-in type, there is no need to check their values; hence, only the latter form should be used.



Core Python Programming
Core Python Programming (2nd Edition)
ISBN: 0132269937
EAN: 2147483647
Year: 2004
Pages: 334
Authors: Wesley J Chun

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net