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 ...
随机推荐
- 阿里云服务器 ECS Ubuntu系统下PHP,MYSQL,APACHE2的安装配置
1.系统更新,必须更新,否则有些软件会找不到. apt-get update apt-get upgrade 2.安装mysql sudo apt-get install mysql-server 3 ...
- How To Mitigate Slow HTTP DoS Attacks in Apache HTTP Server
http://www.acunetix.com/blog/web-security-zone/articles/slow-http-dos-attacks-mitigate-apache-http-s ...
- uniapp打包发版到linux服务器步骤----H5端
最近在写uni-app项目,项目打包部署到服务器后,搞了好一会一直打开是空白页,原来自己有几个地方疏忽了,现把步骤整理一下: 第1步:编辑配置 mainifest.json 文件 tip:运行的基础路 ...
- python-基站位置查询
本文采用的接口是聚合数据提供的 python2.7环境,3.x环境试了下好像不支持,获取位置信息为空 如下为运用代码: #coding=utf-8 ''' Created on 2019年9月18日 ...
- 【持续更新】springboot相关配置
@Configuration public class MyWebMvcConfig implements WebMvcConfigurer { //注册了新的访问路径 @Override publi ...
- 使用net Manager工具远程连接Oracle配置监听
一.在服务端配置Oracle端口 win + R 输入netca 弹出如下窗口后 选择监听程序配置,点击下一步: 二.配置端口号后使用Telnet工具调试端口是否连通 在命令行输入telnet 服务器 ...
- RabbitMQ镜像集群搭建
RabbitMQ 官网 https://www.rabbitmq.com/ 小编使用的系统环境是CentOS7.4 系统 IP hostname CentOS7.4 1.1.1.1 hostname0 ...
- Java多线程--synchronized的用法
全面介绍Synchronized:https://blog.csdn.net/luoweifu/article/details/46613015 synchronized class/this/obj ...
- Rocket - debug - Example: Selecting Harts
https://mp.weixin.qq.com/s/HjG5S9binyniG_amC3Dr5Q 介绍riscv-debug的使用实例:如何选择核心,执行Halt/Resume请求. 1. Sele ...
- Rocket - tilelink - first
https://mp.weixin.qq.com/s/0nzkV4K1osNEQzrtITYxmw 介绍Edges中first/last/done的实现. 1. firstlastH ...