def foo(data): if isinstance(data, int): print 'you entered an integer' elif isinstance(data, str): print 'you entered a string' else: raise TypeError, 'only integers or strings!' from operator import * vec1 = [12, 24] vec2 = [2, 3, 4] opvec = (add, sub, mul, div) for eachOp in opvec: for i in vec1: for j in vec2: print '%s(%d, %d) = %d' % (eachOp.__name__, i, j, eachOp(i, j))
11.1.Introduction | ||||
11.1.1. | Common operator overloading methods | |||
11.1.2. | Double Underscore __ | |||
11.1.3. | Special Class Attributes | |||
11.1.4. | __dict__ is a dictionary representing its attributes: | |||
11.1.5. | Special Instance Attributes | |||
11.1.6. | Built-in Type Attributes | |||
11.1.7. | Metaclass Example | |||
11.1.8. | Related Modules and Documentation |