Comment

Andrew Veitch

I would use:

if type(value) is bool:
elseif type(value) is int:
elseif type(value) is float:

which will work as expected.

Replies

Peter Bengtsson

I like that one! It looks neat and pythonic. Maybe I should stop using isinstance() for basic types and use that weapon more around custom classes and instance objects.

Chris Nasr

This is actually less useful than the original. With this code only bools, integers, and floats would be checked, meaning any subclassing of int or float would not be caught.