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))
Related Scripts with Example Source Code in same category :