1. 程式人生 > >split()函式的用法 Python

split()函式的用法 Python

①Python中有split()和os.path.split()兩個函式,具體作用如下: split():拆分字串。通過指定分隔符對字串進行切片,並返回分割後的字串列表(list) os.path.split():按照路徑將檔名和路徑分割開

②分離檔名和路徑

import os

print(os.path.split('/dodo/soft/python/'))#只有路徑'/dodo/soft/python/'

('/dodo/soft/python', '')

print(os.path.split('/dodo/soft/python'))#路徑'/dodo/soft',檔名python

('/dodo/soft', 'python')