1. 程式人生 > >Python3 join函式和os.path.join用法

Python3 join函式和os.path.join用法

Python3  join函式和os.path.join用法

os.path.join()連線兩個檔名地址的時候,就比os.path.join("D:\","test.txt")結果是D:\test.txt

# Python3
# author:lim
# date:2019-01-14

# 1.對陣列進行操作
seq1 = ['hello','good','boy','doiido']
msg1 = ' '.join(seq1)
print(msg1)
# 輸出結果:hello good boy doiido
msg2 = ','.join(seq1)
print(msg2)
# 輸出結果:hello,good,boy,doiido # 2.對字串操作 seq2 = 'hello good boy doiido' msg3 = ':'.join(seq2) print(msg3) # 輸出結果:h:e:l:l:o: :g:o:o:d: :b:o:y: :d:o:i:i:d:o # 3.對元組進行操作 seq3 = ('hello','good','boy','doiido') msg4 = ':'.join(seq3) print(msg4) # 輸出結果:hello:good:boy:doiido # 4.對字典進行操作 seq4 = {'hello':1,'
good':2,'boy':3,'doiido':4} msg5 = ':'.join(seq4) print(msg5) # 輸出結果:hello:good:boy:doiido # 5.合併目錄 import os msg6 = os.path.join('E:/hello/','/good/boy/','doiido') print(msg6) # 輸出結果:E:/good/boy/doiido