Check if object is a number or boolean
To answer the specific question:
isinstance(x[0], (int, float))
This checks if x[0]
is an instance of any of the types in the tuple (int, float)
.
You can add bool
in there, too, but it's not necessary, because bool
is itself a subclass of int
.
Doc reference:
isinstance()
- built-in numeric types
To comment on your current code, you shouldn't rely on interning of short strings. You are supposed to compare strings with the ==
operator:
x[1] == 'Hip'
Easiest i would say:
type(x) == type(True)