为什么`type(x)== int或float`不起作用?

时间:2014-07-13 10:45:32

标签: python

def distance_from_zero (x):
    if type(x) == int or float :
        return abs(x)
    else:
        return 'Nope'

如果输入为xint,则该函数应返回float的绝对值。
如果输入不是那些,则应返回Nope

我不知道我在这里做错了什么。

1 个答案:

答案 0 :(得分:-3)

您必须使用type(x) == int or type(x) == float

相关问题