关于python里面的join()函数
来源:互联网 发布:炫浪网络社区发书区 编辑:程序博客网 时间:2024/06/05 15:00
os.path.join()它是将多个路径组合后返回
join()连接字符串数组。将字符串、元组、列表中的元素以指定的字符(分隔符)连接生成一个新的字符串。
先说join()
语法: 'sep'.join(seq)
参数说明
sep:分隔符。可以为空
seq:要连接的元素序列、字符串、元组、字典
上面的语法即:以sep作为分隔符,将seq所有的元素合并成一个新的字符串
返回值:返回一个以分隔符sep连接各个元素后生成的字符串
实例:
1.对序列(list)进行操作:
>>> A = ['a','b','c','d','e']
>>> ' '.join(A)
'a b c d e'
>>> '6'.join(A)
'a6b6c6d6e'
2.对字符串进行操作:
>>> A = 'hello,world'
>>> ' '.join(A)
'h e l l o , w o r l d'
>>> '>'.join(A)
'h>e>l>l>o>,>w>o>r>l>d'
3.对元组进行操作:
>>> A = ('h','e','l','l','o')
>>> 'S'.join(A)
'hSeSlSlSo'
>>> ' '.join(A)
'h e l l o'
>>> ''.join(A)
'hello'
4.对dict进行操作:
>>> A = {'a':1,'b':2,'c':3,'d':4,'e':5}
>>> ''.join(A)
'ebacd'
>>> '7'.join(A)
'e7b7a7c7d'
至于os.path.join(),它是将多个路径组合后返回
>>> os.path.join('/hello/','world/','lll')
'/hello/world/lll'
这里要注意hello后面这个/如果放在world前面去了得到的路径就不对了
>>> os.path.join('/hello','/world/','lll')
'/world/lll'
- 关于python里面的join()函数
- python里面的join函数用法及简单示例
- Python 的join函数
- Python 的join函数
- Python 的join函数
- Python的join函数
- python的join函数
- Python的join函数
- python 关于join 函数需要注意的一点
- python里面的函数
- Python 有趣的join函数
- python的join(string)函数
- python join函数的用法
- Python join()函数的使用
- 关于python里面的对齐
- Python里面的partial 函数
- python里面的函数参数
- python join字符连接函数的使用方法
- Ubuntu 16.04下解决sublime text3无法输中文问题
- 寄存器PLC地址与寄存器modbus协议地址
- FreeRTOS 任务创建和删除(静态)
- 如何阅读英文文献
- ARM裸机学习之S5PV210启动方式理解
- 关于python里面的join()函数
- maven入门之maven的坐标和仓库
- XPath
- angularjs过滤敏感字符
- GitHub: (3)版本回退
- Lucene 深入学习(3)Lucene索引初识
- JZOJ5417. 【NOIP2017提高A组集训10.24】方阵
- CODE FESTIVAL 2017 qual C- A-B-C 总结
- 来CSDN耍耍