一,對象
1.對象類型分爲:
a.可變(mutable)對象包括,列表(list)、字典(dictionary);
b.不可變(immutable)對象包括,元組(tuple)、數值(number)、字符串(string);
2.對象的比較:
a.身份比較:用於確定是否是同一對象,例如:id() ;
b.類型比較:用於確定是否同屬於一個類型,例如:type() ;
c.值比較:值是否相同,直接等值比較 ;
3.可調用對象:
a.如何判斷是否可調用,語法:callable() ;
b.可調用對象調用的是,對象中的方法、類、函數;
例如:
In [2]: def printName(): ...: print "Hello" ...: In [4]: callable(printName) Out[4]: True
二,原處修改
1.列表的原處修改
a.list.sort() 原處排序;
b.list.reverse原處逆序;
2.字典
dict.iteritems() 返回生成器,遍歷每個元素;
例如:
In [13]: d1 = {'x':1,'y':2} In [14]: i1 = d1.iteritems() In [15]: i1.next() Out[15]: ('y', 2) In [16]: i1.next() Out[16]: ('x', 1) In [17]: i1.next() --------------------------------------------------------------------------- StopIteration Traceback (most recent call last) <ipython-input-17-be7912f76fe0> in <module>() ----> 1 i1.next() StopIteration:
三,如何獲取對象使用幫助
1.獲取對象支持使用的屬性和方法:
例如:dir(d1)
2.某方法的具體使用幫助:
例如:help(list.pop)
3.獲取可調用對象的文檔字串:
例如:print.obj.__doc__