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; } ...
随机推荐
- JAVA读取文件夹大小的几种方式
(一)单线程递归方式 package com.taobao.test; import java.io.File; public class TotalFileSizeSequential { publ ...
- C++11并发学习之三:线程同步(转载)
C++11并发学习之三:线程同步 1.<mutex> 头文件介绍 Mutex又称互斥量,C++ 11中与 Mutex 相关的类(包括锁类型)和函数都声明在 <mutex> 头文 ...
- XSD文件详解(二)
<?xml version="1.0" encoding="gb2312"?> <studentlist> <student ...
- <mark>元素----黄色背景
当需要引用其他人的内容,或者想要重点标注一段文本时可以使用<mark>元素.这样浏览器会给<mark>中的文本添加黄色背景. 效果图如下:原文:HTML5 - 使用<m ...
- python接口自动化(四十二)- 项目结构设计之大结局(超详解)
简介 这一篇主要是将前边的所有知识做一个整合,把各种各样的砖块---模块(post请求,get请求,logging,参数关联,接口封装等等)垒起来,搭建一个房子.并且有很多小伙伴对于接口项目测试的框架 ...
- COGS 1507. [IOI2000]邮局
1507. [IOI2000]邮局 ★☆ 输入文件:postoffice.in 输出文件:postoffice.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] ...
- WCF基础之大型数据和流
在WCF的实际应用中,有可能存在10M,100M甚至G级别的传输,这个时候我们就不得不考虑编码和传输模式,当然得选择相应的绑定(binding) 如上图所示,我可以直接使用系统提供的相应绑定,然后设置 ...
- 我的Android进阶之旅------>Android中android:windowSoftInputMode的用法
面试题:如何在显示某个Activity时立即弹出软键盘? 答案:在AndroidManifest.xml文件中设置<activity>标签的android:windowSoftInputM ...
- linux环境下redis安装
本篇文章主要说明的是Linux环境下redis数据库的安装: 首先进入目标目录: 下载安装包,执行命令: wget http://download.redis.io/releases/redis-4. ...
- 【转载】解决Apache2+PHP上传文件大小限制的问题
原文出处:http://evol1216.blog.163.com/blog/static/13019958020106783623528/ 在用PHP进行文件上传的操作中,需要知道怎么控制上传文件大 ...