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
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/16659.html