How to determine a Python variable's type?

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

How do I view it?


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.


You may be looking for the type() 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'>

It is so simple. You do it like this.

print(type(variable_name))
链接地址: http://www.djcxy.com/p/23228.html

上一篇: NHibernate ISession刷新:何时何地使用它,为什么?

下一篇: 如何确定一个Python变量的类型?