码迷,mamicode.com
首页 > 编程语言 > 详细

Detect types in python2

时间:2016-01-29 21:15:24      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:

 1 >>> type(bonjour)
 2 <type str>
 3 >>> type(type(bonsoir))
 4 <type type>
 5 >>> dir(_)
 6 [__abstractmethods__, __base__, __bases__, __basicsize__, __call__, __class__, __delattr__, __dict__, __dictoffset__, __doc__, __eq__, __flags__, __format__, __ge__, __getattribute__, __gt__, __hash__, __init__, __instancecheck__, __itemsize__, __le__, __lt__, __module__, __mro__, __name__, __ne__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasscheck__, __subclasses__, __subclasshook__, __weakrefoffset__, mro]
 7 >>> type(2**100).__name__
 8 long
 9 >>> if isinstance(what up, (complex, float, int, long, str)): True
10 
11 True
12 >>> type(123) == type(23333333333333333)
13 False
14 >>> type(123) == type(233)
15 True

There is also a module called types.

1 >>> import types
2 >>> dir(types)
3 [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, __builtins__, __doc__, __file__, __name__, __package__]

Three key properties of all python objects: (ID, TYPE, VALUE)

 

Detect types in python2

标签:

原文地址:http://www.cnblogs.com/ch3cooh/p/python-type-detection.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!