Check the types of arguments in python

def my_abs(x):
    if not isinstance(x, (int, float)):
        raise TypeError('...');
    elif x>0:
        return x;
    else:
        return -x;

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注