----------------------------------------------------------------------------------------------- #!/usr/bin/python # -*- coding: UTF-8 -*- a,b,c,d=20,5.5,True,4+3j print(type(a),type(b),type(c),type(d)) #(<type 'int'>, <type 'float'>, <type 'bool'>, <type 'complex'>) ---------------------------------------------------------------------------------------- #!/usr/bin/python # -*- coding: UTF-8 -*- print(100,type(100)) #(100, <type 'int'>) print('100',type('100')) #('100', <type 'str'>) ---------------------------------------------------------------------------------------- 此外还可以用 isinstance 来判断: #!/usr/bin/python # -*- coding: UTF-8 -*- a = 111 print(isinstance(a, int))#True ---------------------------------------------------------------------------------------- 综合: #!/usr/bin/python # -*- coding: UTF-8 -*- class A: pass class B(A): pass print(isinstance(A(), A)) # returns True print(type(A()) == A ) # returns False print(isinstance(B(), A)) # returns True print(type(B()) == A) # returns False 分享知识,分享快乐!希望中国站在编程之巅!
|
|