比较变量类型 [英] Comparing variable types
问题描述
type(i)=="< type''flora''>"
这总是返回false。为什么?
type(i)返回< type''flora''>如果我是一个浮点数,为什么不= =工作?
> type(i)=="< type' 'float''>"这总是返回false。为什么?
类型(i)返回< type''flora''>如果我是浮点数,那为什么不= =工作?
使用isinstance(),就像这样:
isinstance(i ,浮动)
如果我是浮动,这将返回True,否则返回False。
- Kef
>
" Kill Bill" <双** @ kill.com>在消息中写道
news:bn ************* @ ID-198839.news.uni-berlin.de ...type(i)=="< type''float''>"
这比较当前的i类型(" string"),< type
''str''>。
您可以这样做:i = 1.3
type(i) =="< type''float''>"
False str(type(i))=="< type''flora''>"
True
这总是返回false。为什么?
类型(i)返回< type''flora''>如果我是浮动的,为什么不= =工作?
您可能想要的是:
导入类型
类型(i )== types.FloatType
True
Emile van Sebille
em *** @ fenx.com
blockquote>
你能告诉我你在哪里在docs中发现了这个方法?我遇到了麻烦
浏览它们,java文档更容易查看。
" KefX" <柯********** @ aol.comNOSPAM>在消息中写道
news:20 *************************** @ mb-m07.aol.com。 ..type(i)=="< type''float''>"
这总是返回false。为什么?
类型(i)返回< type''flora''>如果我是一个浮点数,那为什么不= =工作?
使用isinstance(),就像这样:
isinstance(i,float)
这个如果我是浮点数将返回True,否则返回False。
- Kef
type(i) == "<type ''float''>"
this always returns false. How come?
type(i)returns <type ''float''> if i is a float so why isn''t == working?解决方案>type(i) == "<type ''float''>"this always returns false. How come?
type(i)returns <type ''float''> if i is a float so why isn''t == working?
Use isinstance(), like this:
isinstance(i, float)
This will return True if i is a float, False if not.
- Kef
"Kill Bill" <bi**@kill.com> wrote in message
news:bn*************@ID-198839.news.uni-berlin.de...type(i) == "<type ''float''>"
This compares the current type of i to type("string"), which is <type
''str''>.
You can do:i = 1.3
type(i) == "<type ''float''>"
False str(type(i)) == "<type ''float''>" True
this always returns false. How come?
type(i)returns <type ''float''> if i is a float so why isn''t == working?
What you probably want is:
import types
type(i) == types.FloatType True
Emile van Sebille
em***@fenx.com
Can you tell me where you found that method in the docs? I''m having trouble
navigating them, the java docs are so much easier to look at.
"KefX" <ke**********@aol.comNOSPAM> wrote in message
news:20***************************@mb-m07.aol.com...type(i) == "<type ''float''>"
this always returns false. How come?
type(i)returns <type ''float''> if i is a float so why isn''t == working?
Use isinstance(), like this:
isinstance(i, float)
This will return True if i is a float, False if not.
- Kef
这篇关于比较变量类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!