目录
python中的join
str. join():
返回一个由 iterable 中的字符串拼接而成的字符串。 如果 iterable 中存在任何非字符串值包括 bytes 对象则会引发 TypeError。 调用该方法的字符串将作为元素之间的分隔。
test = "test"
a = ' '.join(test)
print(a)
out:
t e s t
test = ("test","a","b")
a = ' '.join(test)
print(a)
output:
test a b
test = {"test":1,"a":2,"b":3}
a = ' '.join(test)
print(a)
output:
test a b
bytes.
join
(iterable)
bytearray.
join
(iterable)
返回一个由 iterable 中的二进制数据序列拼接而成的 bytes 或 bytearray 对象。 如果 iterable 中存在任何非 字节类对象 包括存在 str 对象值则会引发 TypeError。 提供该方法的 bytes 或 bytearray 对象的内容将作为元素之间的分隔。
join()方法就是将可迭代对象中的str或者bytes中的对象拿出来,使用一定的分隔符进行拼接的操作。
python中的os.path.join
将路径连接成一个新的路径,详细见:os模块主要方法介绍