Python中join和split用法实例
join用来连接字符串,split恰好相反,拆分字符串的。
不用多解释,看完代码,其意自现了。
>>>li = ['my','name','is','bob']
>>>' '.join(li)
'my name is bob'
>>>s = '_'.join(li)
>>>s
'my_name_is_bob'
>>>s.split('_')
['my', 'name', 'is', 'bob']
其join和split的英文版解释如下:
join(...)
S.join(sequence) -> string
Return a string which is the concatenation of the strings in the
sequence. The separator between elements is S.
split(...)
S.split([sep [,maxsplit]]) -> list of strings
Return a list of the words in the string S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are removed
from the result.
相关文章
Python实战快速上手BeautifulSoup库爬取专栏标题和地址
BeautifulSoup是爬虫必学的技能,BeautifulSoup最主要的功能是从网页抓取数据,Beautiful Soup自动将输入文档转换为Unicode编码,输出文档转换为utf-8编码2021-10-10
PyQt5实现将Matplotlib图像嵌入到Scoll Area中显示滚动条效果
我想知道是否有一种方法可以在matplotlib上显示滚动条(水平或垂直),显示包含多个子槽(sublot2grid)的页面(plt.show).下面就通过本文给大家分享PyQt5实现将Matplotlib图像嵌入到Scoll Area中显示滚动条效果,对PyQt5 Matplotlib图像嵌入相关知识感兴趣的的朋友一起看看吧2021-05-05
pytorch 在网络中添加可训练参数,修改预训练权重文件的方法
今天小编就为大家分享一篇pytorch 在网络中添加可训练参数,修改预训练权重文件的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2019-08-08
Python实现常见的几种加密算法(MD5,SHA-1,HMAC,DES/AES,RSA和ECC)
这篇文章主要介绍了Python实现常见的几种加密算法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-05-05


最新评论