How to test the data type of a variable
Deac-33 Lancaster
deac33 at gmail.com
Thu Apr 23 21:53:52 EDT 2020
On Thursday, April 23, 2020 at 6:46:14 PM UTC-7, Alan Bawden wrote:
> 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
Alan,
Much thanks for the response. Yes, dynamic typing so it can change. But this is what I was looking for, unable to find it in the docs, need more practice at that. :-)
More information about the Python-list
mailing list