python字符串函数
来源:互联网 发布:ping 是什么端口 编辑:程序博客网 时间:2024/06/03 21:39
split()函数:
string = “www.shenhuxi.com.cn”
1.以’.’为分隔符
print(string.split(‘.’)) ==>[”www’,’shenhuxi’,’com’,’cn’]
2.分割两次
print(string.split(‘.’,2)) ===>[‘www’,’shenhuxi’,’com.cn’]
response是requests的响应
response.url是返回爬取的页面的链接,
filename = response.url.split(“/”)[-2] 分离字符串
3.分割两次
print(string.split(‘.’,2)[1]) =====>分割两次,并且取序列为1的项=====>shenhuxi
二 分离文件名和路径
import os
print(os.path.split(‘/dodo/soft/python/’))
(‘/dodo/soft/python/’,”)
print(os.path.split(‘/dodo/soft/python’))
(‘/dodo/soft’,’python’)
join
list2 = [‘ming’,’tian’,’hui’,’geng’,’hao’]
li = ”.join(list2)
print(li)
mingtianhuigenghao
li = ‘:’join(list2)
ming:tian:hui:geng:hao:
import os
lis = os.path.join(‘/ming/’,’tian/hui/’,’genghao/’)
‘/mingtianhuigenghao’
阅读全文
0 0
- python 字符串处理函数
- python字符串处理函数
- PYTHON-字符串处理函数
- Python字符串处理函数
- Python字符串处理函数
- Python:字符串函数
- PYTHON字符串常用函数
- python 字符串操作函数
- python字符串处理函数
- Python:字符串函数
- python字符串函数归纳
- Python字符串分割函数
- python 字符串处理函数
- python字符串函数
- Python字符串常用函数
- Python字符串处理函数
- python 字符串操作函数
- python 字符串函数
- Java 静态分派与动态分派
- kafka集群broker节点扩容方案
- HDU 6208
- clipse–>run as –> maven test 出现中文乱码
- Cisco Packet Tracer使用方法和路由器基本配置
- python字符串函数
- Android:控件WebView显示网页
- Legal or Not(拓扑排序)
- bzoj 1694 && 1742: [Usaco2005 nov]Grazing on the Run 边跑边吃草(DP)
- Git入门介绍-1-简单介绍
- 数据结构实验之链表八:Farey序列
- C++学习16:引用
- [Java]如何改变字符串中的字符
- 读《第一行代码》遇到问题3:Adb shell中的查表指令