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 字符串属性(四)的更多相关文章

  1. python3 字符串属性(一)

    python3 字符串属性 >>> a='hello world' >>> dir(a) ['__add__', '__class__', '__contains_ ...

  2. python3字符串属性(二)

    1.S.isdecimal() -> bool    Return True if there are only decimal characters in S, False otherwise ...

  3. python3 字符串属性(三)

    maketrans 和 translate的用法(配合使用) 下面是python的英文用法解释 maketrans(x, y=None, z=None, /) Return a translation ...

  4. python系列四:Python3字符串

    #!/usr/bin/python #Python3 字符串#可以截取字符串的一部分并与其他字段拼接var1 = 'Hello World!'print ("已更新字符串 : ", ...

  5. (十四)Python3 字符串格式化

    Python3 字符串格式化 字符串的格式化方法分为两种,分别为占位符(%)和format方式.占位符方式在Python2.x中用的比较广泛,随着Python3.x的使用越来越广,format方式使用 ...

  6. 从零开始学习PYTHON3讲义(四)让程序更友好

    <从零开始PYTHON3>第四讲 先看看上一讲的练习答案. 程序完成的是功能,功能来自于"程序需求"("需求"这个词忘记了什么意思的去复习一下第二讲 ...

  7. Position属性四个值:static、fixed、absolute和relative的区别和用法

    Position属性四个值:static.fixed.absolute和relative的区别和用法 在用CSS+DIV进行布局的时候,一直对position的四个属性值relative,absolu ...

  8. NSAttributedString字符串属性类

    //定义一个可变字符串属性对象aStr NSMutableAttributedString *aStr = [[NSMutableAttributedString alloc]initWithStri ...

  9. 字符串属性使用strong的原因

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

随机推荐

  1. 机器学习5—logistic回归学习笔记

    机器学习实战之logistic回归 test5.py #-*- coding:utf-8 import sys sys.path.append("logRegres.py") fr ...

  2. 第一篇: Ansible 介绍

    应用场景:   BOSS:运维帮忙把所有的服务器tomcat 重启一下,谢谢!(tomcat 服务有2K台) 运维:………… 运维:  啪啪啪啪啪啪啪啪..........(键盘的声音响彻办公室) B ...

  3. 深入了解Erlang 垃圾回收机制以及其重要性(转)

    声明:本片文章是由Hackernews上的[Erlang Garbage Collection Details and Why ItMatters][1]编译而来,本着学习和研究的态度,进行的编译,转 ...

  4. 探究 Redis 4 的 stream 类型

    redis 2 10 月初,Redis 搞了个大新闻.别紧张,是个好消息:Redis 引入了名为 stream 的新数据类型和对应的命令,大概会在年底正式发布到 4.x 版本中.像引入新数据类型这样的 ...

  5. openresty 定时器

    [1]nginx定时器应用 (1)文件目录结构 (2)nginx.conf配置 lua_package_path "/usr/local/lib/ubcsrvd/lualib/?.lua;; ...

  6. UGUI随记

    <color=#ffef00ff>武器</color>:巨剑 <color=#ffef00ff>种族</color>:人族 <color=#ffe ...

  7. (转)linux设备驱动之USB数据传输分析 一

    三:传输过程的实现说到传输过程,我们必须要从URB开始说起,这个结构的就好比是网络子系统中的skb,好比是I/O中的bio.USB系统的信息传输就是打成URB结构,然后再过行传送的.URB的全称叫US ...

  8. 【BZOJ3784】树上的路径 点分治序+ST表

    [BZOJ3784]树上的路径 Description 给定一个N个结点的树,结点用正整数1..N编号.每条边有一个正整数权值.用d(a,b)表示从结点a到结点b路边上经过边的权值.其中要求a< ...

  9. 异常:The JSP specification requires that an attribute name is preceded by whitespace

    The JSP specification requires that an attribute name is preceded by whitespace: 其实这句话翻译就是 属性后面要必须有空 ...

  10. AFN errorCode对应的状态码

    转 http://blog.csdn.NET/wangyanchang21/article/details/50932191 在很多时候都会遇到错误, 还会带有一些 Error Code , 比如在各 ...