1、is instance(arg1,arg2) ?查詢arg1的類型是否是arg2 ? ?
from ? ?collections ? ?import ? ?Iterable
print (isinstance(a,Iterable))
查詢 ?a ?是否是可迭代對象
2、重新導入模塊
調(diào)用某個模塊時,模塊被更改通過imp下reload()方法進行重新加載獲得新模版
import test
from ipm import *
reload(test)
3、字符串處理
合并字符串join() ? 和 ? 格式化字符串format()
'''
#對序列進行操作(分別使用' '與':'作為分隔符)
>>> seq1=['hello','good','boy','doiido']
>>>print' '.join(seq1)
hello good boy doiido
>>>print':'.join(seq1)
hello:good:boy:doiido
#對字符串進行操作
>>> seq2="hello good boy doiido"
>>>print':'.join(seq2)
h:e:l:l:o: :g:o:o:d: :b:o:y: :d:o:i:i:d:o
#對元組進行操作
>>> seq3=('hello','good','boy','doiido')
>>>print':'.join(seq3)
hello:good:boy:doiido
#對字典進行操作
>>> seq4={'hello':1,'good':2,'boy':3,'doiido':4}
>>>print':'.join(seq4)
boy:good:doiido:hello
#合并目錄
>>>importos
>>> os.path.join('/hello/','good/boy/','doiido')
'/hello/good/boy/doiido'
'''
3、enumerate()
enumerate每次回返回一個tuple:(index, value)
在enumerate里面我們可以放置一個iterable的對象,這樣的對象可以是a sequence, an iterator, or some other object which supports iteration。在Python doc 里面看到這樣的解釋之后我便嘗試自己實現(xiàn)一個iterable的對象。實現(xiàn)如下:
