常见字符串操作

print('',end=' ')不换行输出

科学计数法
print(1.3e3)
1300

bin(10)转为二进制
oct()八进制
hex()十六进制

.strip()掐头去尾
.capitalize()首字母大写
.upper()所有字母大写
.center(30,'*')居中,以*填充,总长30
.count()统计
.endswith()判断是否以xx结尾
.find()查找
.format格式化
.index索引
[]切片
.isdigit判断是否数字
.replace替换
x='a'实际上是x=str('a')
.split()分割
.isupper是否全是大写
.isspace是否全是空格
.istitle是否大写开头
.ljust左对齐
.swapcase大小写反转
.title首字母大写

移除空白.strip
分割.split
长度len
索引index
切片[]

原文地址:https://www.cnblogs.com/yx179971/p/6958822.html