How can I type-check variables in Python?

isinstance(n, int)

If you need to know whether it’s definitely an actual int and not a subclass of int (generally you shouldn’t need to do this):

type(n) is int

this:

return int(n) == n

isn’t such a good idea, as cross-type comparisons can be true – notably int(3.0)==3.0

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)