格式化
s = 'hello word'
s.capitalize() #首字母大写
s.center(20,'-') #居中填充
s.ljust(20,'-') #左填充
s.rjust(20,'-') #右填充
s.swapcase() #大小写切换
s.title() #标题模式
s.zfill(8) #不足8位用0补齐
s.strip() #两边去死皮
s.lstrip() #左边去死皮
s.rstrip() #右边去死皮
f'{s}是基础语言' #format用法
判断
s.startswith('h') #判断是以什么开头
s.endswith('d') #判断以什么结尾
s.isalpha() #判断是不是字母
s.isdigit() #判断是不是数字(只能判断整数)
s.islower() #判断是不是小写字母
s.isupper() #判断是不是大写字母
s.isspace() #判断是不是空格
s.isidentifier() #判断能布恩那个做变量名
s.isnumeric() #判断是不是数字(与isdigit的区别是可以判断中文的数字) s = '一百'
s.istitle() #判断是不是标题格式
字符串 增删改查
s.find('i',1,5) #切片查找,返回[1:5]从左往右中第一个i的下标
s.rfind('lo') #从右边开始找
s.index('o') #返回o的下标,找不到报错
s.count('l') #计数l出现了几次
s.split(' ') # 按空格切割,返回一个列表
s.split(maxsplit=2) #按空格,切两次
s.splitlines() #按行切割
s.removeprefix() #冲前面开始删除
s.removesuffix() #从后面开始删除
s.replace('l','L',3) #L替换l 3次