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 ...
随机推荐
- python3.x 基础三:字符集问题
总结了一张表,更详细信息百度百科: 序号 年份 编码 标准协会 特点 二进制长度 字符长度 表现 1 1967 ASCII 美国国家标准学会(American National Standard In ...
- 消息队列RabbitMQ的安装配置与PHP中的使用
一.RabbitMQ安装 windows安装 下载地址: https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.3/ra ...
- Vue 更换页面图标和title
1.基础的做法就是直接换掉,logo换的时候需要使用icon格式的图标 title 直接在index.html 里面把原来的title注释掉 或者直接改了就行 2. 如果需要进行相应的改变啥的 ,需要 ...
- 深入理解JS:执行上下文中的this(一)
目录 执行上下文与执行上下文栈 this 全局环境 函数环境 总结 参考 1.执行上下文与执行上下文栈 (1)什么是执行上下文? 在 JavaScript 代码运行时,解释执行全局代码.调用函数或使用 ...
- 一文带你了解nginx基础
学习nginx,就要先了解什么是nginx,为什么使用nginx,最后才是了解怎么使用nginx nginx简介 nginx安装 一.Linux中安装nginx 二.Docker中安装nginx 三. ...
- 前端基础进阶(六):在chrome开发者工具中观察函数调用栈、作用域链与闭包
在前端开发中,有一个非常重要的技能,叫做断点调试. 在chrome的开发者工具中,通过断点调试,我们能够非常方便的一步一步的观察JavaScript的执行过程,直观感知函数调用栈,作用域链,变量对象, ...
- AdaBoost理解
AdaBoost是一种准确性很高的分类算法,它的原理是把K个弱分类器(弱分类器的意思是该分类器的准确性较低),通过一定的组合(一般是线性加权进行组合),组合成一个强的分类器,提高分类的准确性. 因此, ...
- Cypress系列(3)- Cypress 的初次体验
如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 这里的栗子项目时 Cypress ...
- 50个SQL语句(MySQL版) 问题七
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- Beta冲刺 —— 5.30
这个作业属于哪个课程 软件工程 这个作业要求在哪里 Beta冲刺 这个作业的目标 Beta冲刺 作业正文 正文 github链接 项目地址 其他参考文献 无 一.会议内容 1.讨论并解决每个人存在的问 ...