python中join函数
"sep".join(iterable)
join用于以指定分隔符将可迭代对象【成员必须为str类型】连接为一个新的字符串,分隔符可以为空
返回值位字符串
os.path.join(path,path1,...)
返回多个路径拼接后的路径【第一个绝对路径之前的参数被忽略】
示例:
import os
string = "test"
lis = ['w', 'e', 'q']
tpl = ('w', 'e', 'q')
dic = {"55": 5, "44": 4, "22": 2, "33": 3, "11": 1}
print("11".join(string)) # a = "11".join(string) print(a) print(type(a))
print("".join(tpl))
print(" ".join(lis))
print("key is : [%s] " % (",".join(dic)))# 字符串去重并按从大到小排列
words = "wsasdeddcewtttwssa"
words_set = set(words) # 集合特性实现去重 字符串集合化
words_list = list(words_set) # 集合列表化
words_list.sort(reverse=True) # 设置排序为从大到小
new_words = "".join(words_list) # join方法以空位分隔符拼接列表元素位新字符串
print(words_list)
print(new_words)print(os.pat
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
