Discuss / Python / 有个问题,为啥我输入 1 也是bad operand type

有个问题,为啥我输入 1 也是bad operand type

Topic source

大大张宇

#1 Created at ... [Delete] [Delete and Lock User]
def my_abs(x):
    if not isinstance(x, (int, float)):
        raise TypeError('bad operand type')
    if x >= 0:
        return x
        print(x)
    else:
        return -x
        print(-x)
x = input()
my_abs(x)

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

你输入的是'1',不是1


  • 1

Reply