Python字符串处理 - str/bytes
1. str
str.count(sub[, start[, end]])
str.encode(encoding="utf-8", errors="strict")
str.format(*args, **kwargs) # s = "this is from {}".format(__file__)
str.find(sub[, start[, end]]) # 没有查找到子串,返回-1
str.rfind(sub[, start[, end]]) # 没有查找到子串,则报Except
str.index(sub[, start[, end]])
str.replace(old, new[, count])
str.join(iterable)
str.split(sep=None, maxsplit=-1)
str.splitlines([keepends]) # keepends: 在输出结果里是否保留换行符('\r', '\r\n', '\n'),默认为False,不包含换行符;如果为True,则保留换行符。
str.strip([chars])
str.lstrip([chars])
str.rstrip([chars])
str.partition(sep) # 通过sep将字符串分成三部分
str.rpartition(sep)
In [85]: "what do you do wait".rpartition("do")
Out[85]: ('what do you ', 'do', ' wait')
str.expandtabs(tabsize=8) # 把字符串中的 tab 符号('\t')转为空格
str.zfill(width) # 返回指定长度width的字符串,原字符串右对齐,前面填充0
str.upper()
str.lower()
str.islower()
c.isalpha() # 字母
c.isdecimal() # Unicode数字,,全角数字(双字节)
c.isdigit() # Unicode数字,byte数字(单字节),全角数字(双字节),罗马数字
c.isnumeric() # Unicode数字,全角数字(双字节),罗马数字,汉字数字
str.startswith(prefix[, start[, end]])
str.endswith(suffix[, start[, end]])
eval(source[, globals[, locals]]) # 将str作为有效表达式并返回结果
2. bytes / bytearray
classmethod
- fromhex(string)
- encode()
bytes.count(sub[, start[, end]])
bytes.decode(encoding="utf-8", errors="strict")
bytearray.decode(encoding="utf-8", errors="strict")
bytes.find(sub[, start[, end]])
bytearray.find(sub[, start[, end]])
bytes.join(iterable)
bytearray.join(iterable)
bytes.replace(old, new[, count])
bytearray.replace(old, new[, count])
bytes.startswith(prefix[, start[, end]])
bytearray.startswith(prefix[, start[, end]])
3. printf-style String Formatting
Python字符串处理 - str/bytes的更多相关文章
- Python字符串(Str)详解
字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可 字符串的格式 b = "hello itcast. ...
- (转)Python 字符串格式化 str.format 简介
原文:https://www.cnblogs.com/wilber2013/p/4641616.html http://blog.konghy.cn/2016/11/25/python-str-for ...
- Python字符串(str)方法调用
# str# n = 'pianYU'# v = n.capitalize() # 将字符串的首字母大写# print(v)## n = 'pianYI'# v1 = n.isupper() # 判断 ...
- python 字符串(str)和列表(list)的互相转换
1.str to list str1 = "12345"list1 = list(str1)print list1 str2 = "123 sjhid dhi" ...
- python 字符串编码 str和unicode 区别以及相互转化 decode('utf-8') encode('utf-8')
- python 字符串(str)
- Python 字符串基本操作
字符串是Python的一种基本类型,字符串的操作包括字符串格式化输出.字符串的截取.合并,字符串的查找和替换等操作. 字符串定义 Python中有3种表示字符串的方法:单引号.双引号.三引号.引号使用 ...
- python字符串截取
python字符串截取 str = 'abcd' str[0:-1],-1表示末尾开始的位置,但是[]操作符不取尾下标所对应的字符: 所以str[0:-1] ---->‘abc' str[0:1 ...
- Python入门篇-基础数据类型之整型(int),字符串(str),字节(bytes),列表(list)和切片(slice)
Python入门篇-基础数据类型之整型(int),字符串(str),字节(bytes),列表(list)和切片(slice) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Py ...
随机推荐
- 关于Docker的实践
docker 安装 wget -qO- https://get.docker.com/ | sh 镜像 images search pull commit build tag 查看本地镜像:docke ...
- Storm-Mongodb详解
这两天研究Trident,踩坑踩的遭不住,来和大家分享下. 首先写入数据库: 先看官方API给我们提供的方法: //这是用来辅助下面MongoInsert的简单实现类 public class Sim ...
- maven开发SSH
虽然开发SSH的基本步骤都差不多,但每次都从头开始做真的会有点儿烦,把maven的SSH框的基本代码放出来,下次就可以复制粘贴哈哈. 1. 配置文件: (1)pom.xml <project x ...
- iOS 数组遍历过程中移除
参考:https://blog.csdn.net/u011619283/article/details/53135502 常见crash 原因是数组在移除元素后,继续遍历会有越界问题. 解决思路: 遍 ...
- 【Mood】出大问题(最近很喜欢说这句话)
开学两周啦,第一周来了一次开学考,是崩了,还好没公布成绩和排名. 这两周下了一个很大的决心,准备转型/专注文化课,初三一次信息学奥赛比赛后就不学了,先保证能上高中重点班(如果有的话). 因为现在起步太 ...
- Python 图像处理 OpenCV (5):图像的几何变换
前文传送门: 「Python 图像处理 OpenCV (1):入门」 「Python 图像处理 OpenCV (2):像素处理与 Numpy 操作以及 Matplotlib 显示图像」 「Python ...
- 解决docker创建的elasticsearch-head容器不能连接elasticsearch等问题
在使用docker创建elasticsearch-head容器去连接elasticsearch的时候,容易出两个问题 1.不能连接elasticsearch 修改elasticsearch.yml文件 ...
- windows环境下Kubernetes及Docker安装(那些坑)
k8s 和 Docker容器技术,当前非常流行的技术. 让人日狗的是, 这套技术栈对CN的donet 程序员不怎么友好.娓娓道来,1. 好多镜像都是需要梯子才能访问: 2. window程序员天生 ...
- SQL查找大小为n的连续区间
数据准备 create table sequence ( seq int not null primary key ); insert into values(3); insert into valu ...
- WebStorm 2019.3.1 破解 永久使用 亲测100%成功
声明:本教程 WebStorm 破解补丁.激活码均收集于网络,请勿商用,仅供个人学习使用,如有侵权,请联系作者删除. 前言 今天问公司前端的美眉,你的激活码哪里来的,她说淘宝买的,我说给我用一下,当时 ...