Functions #19 "Review Built In Functions"


#1

The question asks to make an if statement that recognizes if the input is an 'int' or 'float'. I tried writing this as

if type(x) == int or float:

but apparently that doesn't work, it has to be written,

if type(x) == int or type(x) == float:

Is there a way to combine this statement like the one I wrote first?


#2

This would also include types that inherit int/float (bool for example):

isinstance(x, (int, float))

To compare equality to multiple values, use in:

type(x) in (int, float)


#3

Hey thanks for the reply!

So using 'in' would make the 'if' statement act the way I expected it to originally?