python3 字符串属性(四)
1、
S.partition(sep) -> (head, sep, tail)
Search for the separator sep in S, and return the part before it,
the separator itself, and the part after it. If the separator is not
found, return S and two empty strings.
分割作用,参数为分割字符,分为三部分,(参数前,参数,参数后);如果参数没有找到,返回原字符串和两个空字符串。参数有多个,以第一个为准。S.partition(sep) -> (head, sep, tail) 以最后一个参数为准。
>>> a
'acbsdwf124'
>>> a.partition('d')
('acbs', 'd', 'wf124')
>>> a.partition('i')
('acbsdwf124', '', '')
>>> a.partition('sd')
('acb', 'sd', 'wf124')
>>> a='hello world hello huhu !'
>>> a.partition('hello')
('', 'hello', ' world hello huhu !')
2、
S.replace(old, new[, count]) -> str
Return a copy of S with all occurrences of substring
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced.
替换
>>> a='1a2a3a4a5a'
>>> a.replace('a','b')
'1b2b3b4b5b
>>> a.replace('a','b',)
'0b1b2b3a4a5a #替换前三个
3、
S.split(sep=None, maxsplit=-1) -> list of strings
Return a list of the words in 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.
S.rsplit(sep=None, maxsplit=-1) -> list of strings 第二个参数,从右侧开始划分。
文本解析,默认为空格,空格将被移除。返回字符串列表。
>>> a='hello world ,huhu !'
>>> a.split()
['hello', 'world', ',huhu', '!']
>>> a.split(',')
['hello world ', 'huhu !']
>>> a='hello:world:huhu'
>>> a.split(':',)
['hello', 'world', 'huhu']
>>> a.split(':',)
['hello', 'world:huhu'] #从左侧划分。
S.splitlines([keepends]) -> list of strings
Return a list of the lines in S, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends
is given and true
>>> a="""hello world!
... second line
... splitlins test
... """
>>> a.splitlines()
['hello world!', 'second line', 'splitlins test']
>>> a.splitlines(True) #保留行分割符
['hello world!\n', 'second line\n', 'splitlins test\n']
4、
S.swapcase() -> str
Return a copy of S with uppercase characters converted to lowercase
and vice versa.
字母大小写转换
>>> a='ABCDefgh'
>>> a.swapcase()
'abcdEFGH'
5、
S.zfill(width) -> str
Pad a numeric string S with zeros on the left, to fill a field
of the specified width. The string S is never truncated.
给定长度,左侧添零补充
>>> a
'ABCDefgh'
>>> a.zfill()
'00ABCDefgh'
python3 字符串属性(四)的更多相关文章
- python3 字符串属性(一)
python3 字符串属性 >>> a='hello world' >>> dir(a) ['__add__', '__class__', '__contains_ ...
- python3字符串属性(二)
1.S.isdecimal() -> bool Return True if there are only decimal characters in S, False otherwise ...
- python3 字符串属性(三)
maketrans 和 translate的用法(配合使用) 下面是python的英文用法解释 maketrans(x, y=None, z=None, /) Return a translation ...
- python系列四:Python3字符串
#!/usr/bin/python #Python3 字符串#可以截取字符串的一部分并与其他字段拼接var1 = 'Hello World!'print ("已更新字符串 : ", ...
- (十四)Python3 字符串格式化
Python3 字符串格式化 字符串的格式化方法分为两种,分别为占位符(%)和format方式.占位符方式在Python2.x中用的比较广泛,随着Python3.x的使用越来越广,format方式使用 ...
- 从零开始学习PYTHON3讲义(四)让程序更友好
<从零开始PYTHON3>第四讲 先看看上一讲的练习答案. 程序完成的是功能,功能来自于"程序需求"("需求"这个词忘记了什么意思的去复习一下第二讲 ...
- Position属性四个值:static、fixed、absolute和relative的区别和用法
Position属性四个值:static.fixed.absolute和relative的区别和用法 在用CSS+DIV进行布局的时候,一直对position的四个属性值relative,absolu ...
- NSAttributedString字符串属性类
//定义一个可变字符串属性对象aStr NSMutableAttributedString *aStr = [[NSMutableAttributedString alloc]initWithStri ...
- 字符串属性使用strong的原因
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
随机推荐
- [WebGL入门]二十五,点光源的光照
注:文章译自http://wgld.org/,原作者杉本雅広(doxas),文章中假设有我的额外说明.我会加上[lufy:].另外,鄙人webgl研究还不够深入,一些专业词语.假设翻译有误,欢迎大家指 ...
- maven 常用的环境插件
<build> <finalName>yycgproject</finalName> <plugins> <!-- 修改jdk插件 --> ...
- [转]mysqlx 同时使用 AND OR
- 微信小程序之如何注册微信小程序
所有文章均是CSDN博客所看,已按照作者要求,注明出处了,感谢作者的整理! 博客文章地址:http://blog.csdn.net/michael_ouyang/article/details/546 ...
- 解决ubuntu无法进入unity模式
终端输入如下命令: 1.sudo add-apt-repository ppa:gnome3-team/gnome3 2.sudo apt-get update 3.sudo apt-get inst ...
- mybatis 视频总结
[说明]mabatis卡住了,理解的不深,配置文件的格式太多看不懂(除了连接数据库的部分),听说还可以和log4j集成,怎么个方法 一:今日完成 1)一些语言细节和操作细节 比如在servlet里面操 ...
- EasyNVR结合阿里云/腾讯云CDN实现微信/小程序直播的方案
背景需求: 许多客户有这样的需求:微信公众号做为平台来对摄像机进行直播:可以让用户随时随地打开公共号就可以观看:保证画面的流畅性:保证视频的并发访问量等. 问题分析: 虽然需求看似很简单,其实真正实现 ...
- Spring MVC的视图解析器
一.视图解析器简介 在Spring MVC中,当Controller将请求处理结果放入到ModelAndView中以后,DispatcherServlet会根据ModelAndView选择合适的视图进 ...
- 自定义弹窗 VS AlertDialog分享弹窗
一.摘要 弹窗通常用于提示用户进行某种操作,比如:点击分享按钮,弹窗分享对话框:双击返回按钮,弹窗退出对话框:下载文件,提示下载对话框等等,分享对话框/退出对话框/下载对话框,都可以直接使用Alert ...
- JITWatch工具
JITWatch,执行程序时监测Java HotSpot JIT编译器如何运作的工具,有助于做JVM的性能优化 wiki: https://github.com/AdoptOpenJDK/jitwat ...