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
上一篇:在安卓上用Termux安装sqlmap


下一篇:Python os.path.dirname(__file__) 与 Python os.path.abspath(__file__) 与 os.system() 函数