Need help from review section of build in


#1

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)
   
    else:
        return "Nope"

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

#2

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


#3

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


#4

(A):

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)


#5

Appreciate for your assistance!!