python isinstance 类型判断
程序员文章站
2024-03-17 18:19:46
...
def my_abs(x):
if not isinstance(x, (int, float)):
raise TypeError('bad operand type')
if x >= 0:
return x
else:
return -x