samedi 10 octobre 2015

Difference between 2 if statements [duplicate]

This question already has an answer here:

Hey I was wondering why this first piece of code is different than the second, the first piece of code takes in True and outputs 1 while the second one correctly outputs "nope". To me both if statements should produce the same output.

1.

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

2.

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

Aucun commentaire:

Enregistrer un commentaire