How to test the data type of a variable

Alan Bawden alan at csail.mit.edu
Thu Apr 23 21:46:04 EDT 2020


Deac-33 Lancaster <deac33 at gmail.com> writes:

> I'm aware that you can find the type of a variable with 
>    type(var)

(Strictly speaking, variables don't have types.  This gives you the type of
the variable's current value.  But we know what you meant.)

> But are there Boolean operators in Python3.8 to test the data type, e.g.
>   is_floate(var)
>   is_string(var)
> etc. ?

You should probably be using isinstance(), as in:
  isinstance(var, float)
  isinstance(var, str)

-- 
Alan Bawden


More information about the Python-list mailing list