type 用法小结:
type()在python中显示括号里的值的属性:
如:
i={1,2,3,4};
type(i);
<type 'set'>
i='hello';
type(i);
<type 'str'>
d = {'Michael': 95, 'Bob': 75, 'Tracy': 85};
type(d);
<type 'dict'>
i=True;
type(i);
<type 'bool'>
如:
>>> mylist=[1,1.0,1.0j,'1',(1,),[1]];
>>> for i in mylist:
... print i,"\t",type(i)
...
1 <type 'int'>
1.0 <type 'float'>
1j <type 'complex'>
1 <type 'str'>
(1,) <type 'tuple'>
[1] <type 'list'>
诸如此类,皆可以用type()显示其属性。