判断类型可以用两种方法
1:
import types
type(x) is types.IntType # 判断是否int 类型
type(x) is types.StringType #是否string类型
... ...
2:
type(x) == type(1) # 是否 int 类型
type(x) in (type(u'') , type('')): # 是否string, unicode类型
1:
import types
type(x) is types.IntType # 判断是否int 类型
type(x) is types.StringType #是否string类型
... ...
2:
type(x) == type(1) # 是否 int 类型
type(x) in (type(u'') , type('')): # 是否string, unicode类型
本文介绍了如何使用Python的types模块和直接比较类型属性来判断变量的类型,包括int和string类型的判断。
7434

被折叠的 条评论
为什么被折叠?



