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. Tomcat9源码分析:BootStrap

    概览 BootStrap源码所在的位置是:org.apache.catalina.startup.Bootstrap 这个类是Tomcat项目的启动类,也就是main函数所在的地方,起始tomcat就 ...

  2. Android Java 线程池 ThreadPoolExecutor源代码篇

    线程池简单点就是任务队列+线程组成的. 接下来我们来简单的了解下ThreadPoolExecutor的源代码. 先看ThreadPoolExecutor的简单类图,对ThreadPoolExecuto ...

  3. 从零开始学android -- Service

    废话不多说了,Service是四大组件之一,是一个后台处理长时间运行在主线程不需要依赖ui界面显示的应用组件,切记不能在service中做耗时操作,会阻塞主线程,要做也要在service中开个子线程做 ...

  4. [转]Unity Shader 学习总结

    1.先来一段单张纹理贴图的shader示例代码: // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClip ...

  5. (总结)RHEL/CentOS 7.x的几点新改变

    一.CentOS的Services使用了systemd来代替sysvinit管理 1.systemd的服务管理程序: systemctl是主要的工具,它融合之前service和chkconfig的功能 ...

  6. Educational Codeforces Round 1 (C) (atan2 + long double | 大数)

    这题只能呵呵了. 东搞西搞,折腾快一天,最后用了一个800多行的代码AC了. 好好的题目你卡这种精度干啥. 还有要卡您就多卡点行不,为什么long double 又可以过... 废了N长时间写个了不管 ...

  7. EasyDSS视频点播服务器实现多分辨率/多码率无缝切换的办法

    EasyDSS流媒体音视频直播与点播服务器软件,是一套提供一站式的转码.点播.直播.检索.回放.录像下载服务的高性能RTMP/HLS/HTTP-FLV流媒体服务,极大地简化了流媒体相关业务的开发和集成 ...

  8. oracle img 导入dmp文件

    1.新建表空间 因为我们导出的数据表的表空间不一定是USERS, 假如说是:FQDB 新建表空间SQL语句 create tablespace FQDB datafile 'c:\FQDB.dbf' ...

  9. 4.AutowireCapableBeanFactory 自动装配工厂

    AutowireCapableBeanFactory 根据名称:自动装配的BeanFactory,其实也是对BeanFactory的增强 源代码: /* * Copyright 2002-2016 t ...

  10. nginx学习之反向代理篇(六)

    在本节,你将学会: --如何根据不同的协议,将请求转发到后端服务器: --修改发送到后端服务器的请求头: --以及配置是否buffering从后端服务器返回来的响应. 1. 将请求转发给后端服务器 当 ...