
有时我们需要知道变量类型,但我们不知道如何检查
isinstancee内置函数(object, (type1,type2...))
isinstance('content',str)返回
TrueorFalse
使用内置函数typepe(object)
type()是查看数据类型最实用、最简单的方法。type()它是一个内部构建的函数,通过调用它可以获得一个反回值,从而知道要查询的正确性。
类型信息。
使用type的方法
>>>type(1)
<type'int'>#返回整形
>>>type('content')
<type'str'>#返回字符串type返回值属于type类型
>>>type(type(1)) <type'type'>#返回type类型
更多技术请关注Python视频教程。