数据类型检查可以用内置函数isinstance
实现:
1 def my_abs(x): 2 if not isinstance(x, (int, float)): 3 raise TypeError('bad operand type') 4 if x >= 0: 5 return x 6 else: 7 return -x
http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00137473843313062a8b0e7c19b40aa8f31bdc4db5f6498000