示例:
>>> import types
>>> type([])
<type 'list'>
>>> type([]) is types.ListType
True
>>> print type.__doc__
type(object) -> the object's type
type(name, bases, dict) -> a new type
>>> print types.__doc__
Define names for all type symbols known in the standard interpreter.
Types that are part of optional modules (e.g. array) are not listed.
>>> print ''.join("%s /n" % e for e in dir(types) if e[:2]!='__')
BooleanType
BufferType
BuiltinFunctionType
BuiltinMethodType
ClassType
CodeType
ComplexType
DictProxyType
DictType
DictionaryType
EllipsisType
FileType
FloatType
FrameType
FunctionType
GeneratorType
GetSetDescriptorType
InstanceType
IntType
LambdaType
ListType
LongType
MemberDescriptorType
MethodType
ModuleType
NoneType
NotImplementedType
ObjectType
SliceType
StringType
StringTypes
TracebackType
TupleType
TypeType
UnboundMethodType
UnicodeType
XRangeType
本文通过Python代码示例展示了如何使用内置的type函数进行类型检查,并介绍了types模块中定义的各种类型符号,包括基本数据类型如列表、整数等。
4万+

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



