为什么用print()来写报错对应的结果无报错?

```def r(k):
if not isinstance(k,(int,float)):
******print('TypeError:bad oper and type')******
if k>0:
return k

k='a'
(之后无结果)

图片说明

首先你都没执行r,何谈报错,其次你两个if它运行会都进行判断,你给k传'a'时,会在第二个if报错,应该改成elif k>0,也就是

    def r(k):
        if not isinstance(k, (int, float)):
            print('TypeError:bad oper and type')
        elif k > 0:
            return k
    k = 'a'
    r(k)