Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

python - 如何确定Python变量的类型?(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.?

(如何查看变量的类型,无论是无符号32位,带符号16位等等?)

How do I view it?

(我该如何看待它?)

  ask by user46646 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

(Python没有与C / C ++相同的类型,这似乎是你的问题。)

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.

(但是,在Python 3.0中,int和long之间的区别消失了。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...