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)   以最后一个参数为准。

  1. >>> a
  2. 'acbsdwf124'
  3. >>> a.partition('d')
  4. ('acbs', 'd', 'wf124')
  5. >>> a.partition('i')
  6. ('acbsdwf124', '', '')
  7. >>> a.partition('sd')
  8. ('acb', 'sd', 'wf124')
  9. >>> a='hello world hello huhu !'
  10. >>> a.partition('hello')
  11. ('', '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.

替换

  1. >>> a='1a2a3a4a5a'
  2. >>> a.replace('a','b')
  3. '1b2b3b4b5b
  4. >>> a.replace('a','b',)
  5. '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  第二个参数,从右侧开始划分。

文本解析,默认为空格,空格将被移除。返回字符串列表。

  1. >>> a='hello world ,huhu !'
  2. >>> a.split()
  3. ['hello', 'world', ',huhu', '!']
  4. >>> a.split(',')
  5. ['hello world ', 'huhu !']
  6. >>> a='hello:world:huhu'
  7. >>> a.split(':',)
  8. ['hello', 'world', 'huhu']
  9. >>> a.split(':',)
  10. ['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

  1. >>> a="""hello world!
  2. ... second line
  3. ... splitlins test
  4. ... """
  5. >>> a.splitlines()
  6. ['hello world!', 'second line', 'splitlins test']
  7. >>> a.splitlines(True) #保留行分割符
  8. ['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.

字母大小写转换

  1. >>> a='ABCDefgh'
  2. >>> a.swapcase()
  3. '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.

给定长度,左侧添零补充

  1. >>> a
  2. 'ABCDefgh'
  3. >>> a.zfill()
  4. '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. JAVA读取文件夹大小的几种方式

    (一)单线程递归方式 package com.taobao.test; import java.io.File; public class TotalFileSizeSequential { publ ...

  2. find 多文件查找需要单引号

    [root@db01 local]# find  -name '*.com'|xargs egrep "qq"./tt.com:qq[root@db01 local]# find  ...

  3. HTTP响应头缓存控制

    在一般Web开发中,有时需要设置特殊的HTTP响应头阻止客户端(一般是浏览器)缓存(使用)该次请求的响应. 这时候大部分开发人员都是百度或谷歌几段代码复制粘贴即了事. 以下简述一下关于缓存控制的几种H ...

  4. thinkPHP5.0的学习研究【基础】

    2017年6月19日13:25:56 基础:1.ThinkPHP5的环境要求如下: PHP >= 5.4.0        PDO PHP Extension        MBstring P ...

  5. [Oracle]根据字段值全库搜索相关数据表和字段

    这个需求比较冷门,但对于在某些特定的情况下,还是会有这样的需要的.好在Oracle实现还比较方便,用存储过程则轻松实现. 查询字符串: create or replace procedure sear ...

  6. apache .htaccess实现301重定向

    <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On #301定向 RewriteCond %{HTTP_HO ...

  7. Linux里的发消息

    1.给指定用户发送消息 语法: write 用户名 说明: 1.用户是在线的 2.执行过程 a.敲完命令按回车,进入写信模式 b.写信的时候如果写错了Ctrl+退格 删除字符 c.写完以后Ctrl+D ...

  8. linux系统环境下搭建coreseek(+mmseg3) (good)

    1.下载并解压coreseek软件,操作命令如下: wget http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz 说明:文件下 ...

  9. Java基础教程:反射基础

    Java基础教程:反射基础 引入反射 反射是什么 能够动态分析类能力的程序称为反射. 反射是一种很强大且复杂的机制. Class类 在程序运行期间,Java运行时系统始终为所有对象维护一个被称为运行时 ...

  10. 3.15课·········out传值(传址)

    public void Hs(out int a, out int b) { a = 4; b = 6; a = b++;//a=6,b=b+1=7//b先赋值给a,然后b+1 b = ++a;//a ...