Categories
python types

How to determine a Python variable’s type?

2028

How do I see the type of a variable? (e.g. unsigned 32 bit)

3

514

You may be looking for the type() built-in function.

See the examples below, but there’s no “unsigned” type in Python just like Java.

Positive integer:

>>> v = 10
>>> type(v)
<type 'int'>

Large positive integer:

>>> v = 100000000000000
>>> type(v)
<type 'long'>

Negative integer:

>>> v = -10
>>> type(v)
<type 'int'>

Literal sequence of characters:

>>> v = 'hi'
>>> type(v)
<type 'str'>

Floating point integer:

>>> v = 3.14159
>>> type(v)
<type 'float'>

1

  • 1

    I had to double take when I saw this. Java SE8 now contains unsigned integers, and I’ve developed so much with it that it seems sinful that Java never had unsigned integers before SE8.

    Nov 26, 2018 at 15:39

204

It is so simple. You do it like this.

print(type(variable_name))

0