How to determine a Python variable's type?


Question

How do I see the type of a variable whether it is unsigned 32 bit, signed 16 bit, etc.?

How do I view it?

1
1349
9/16/2017 9:37:11 AM

Python doesn't have the same types as C/C++, which appears to be your question.

Try this:

>>> i = 123
>>> type(i)
<type 'int'>
>>> type(i) is int
True
>>> i = 123456789L
>>> type(i)
<type 'long'>
>>> type(i) is long
True
>>> i = 123.456
>>> type(i)
<type 'float'>
>>> type(i) is float
True

The distinction between int and long goes away in Python 3.0, though.

1200
12/31/2008 10:43:07 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon