Check if object is a number or boolean

Python 2

import types

x = False
print(type(x) == types.BooleanType) # True

Python 3

# No need to import types module
x = False
print(type(x) == bool) # True

Easiest i would say:

type(x) == type(True)

In python3 this would be: type(x)==bool see example.


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'