Python split()方法 网页地址解析: #coding=utf-8 str=”http://www.runoob.com/python/att-string-split.html” print(“0:%s”%str.split(“/”)[-1]) print(“1:%s”%str.split(“/”)[-2]) print(“2:%s”%str.split(“/”)[-3]) print(“3:%s”%str.split(“/”)[-4]) print(“4:%s”%str.split(“/”)[-5]) print(“5:%s”%str.split(“/”,-1)) print(“6:%s”%str.split(“/”,0)) print(“7:%s”%str.split(“/”,1)) print(“8:%s”%str.split(“/”,2)) print(“9:%s”%str.split(“/”,3)) print(“10:%s”%str.split(“/”,4)) print(“11:%s”%str.split(“/”,5)) 结果是: 0:att-string-split.html 1:python 2:www.runoob.com 3: 4:http: 5:[‘http:’, ”, ‘www.runoob.com’, ‘python’, ‘att-string-split.html’] 6:[‘http://www.runoob.com/python/att-string-split.html’] 7:[‘http:’, ‘/www.runoob.com/python/att-string-split.html’] 8:[‘http:’, ”, ‘www.runoob.com/python/att-string-split.html’] 9:[‘http:’, ”, ‘www.runoob.com’, ‘python/att-string-split.html’] 10:[‘http:’, ”, ‘www.runoob.com’, ‘python’, ‘att-string-split.html’] 11:[‘http:’, ”, ‘www.runoob.com’, ‘python’, ‘att-string-split.html’]David David 183*971@sigusoft.com6年前 (2018-03-14)
2024最新激活全家桶教程,稳定运行到2099年,请移步至置顶文章:https://sigusoft.com/99576.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。 文章由激活谷谷主-小谷整理,转载请注明出处:https://sigusoft.com/36223.html