Need help from review section of build in


what's the difference between the following codes
(specifically, what the difference of == int or float: and == int or type(num) ==float:)

(A)def distance_from_zero(num):
    if type(num) == int or float:
        return abs(num)
        return "Nope"

(B)def distance_from_zero(num):
    if type(num) == int or type(num) ==float:
        return abs(num)
        return "Nope"


float seems to be considered true:

if float:
    print True

so (A) will always be true, since float is always true, while b is only true if the number is actually a float or a integer


thanks for your response,
yet, I am still confused, can you elaborate it ?



if type(num) == int or float:

lets say num is "six", then num == int is false. but float is true (if float: print True) true or false is true.

for b, both would be false as it should be. since it is neither a integer or float

Look, in (A) on the right side (float) is evaluated if true. It is not actually compared with num. it just looking at the float keyword, that is it. Which is considered true (just like positive integers and so on)


Appreciate for your assistance!!