一、字符串的基本操作
查看字符串长度:len(str)
根据索引值提取数据:str[num]
查看特定字符的索引值:str.index('加')
如果一个字符串一个值出现两次,那么打印的索引值就是那个字第一次出现的索引值
str = 'hello,武汉加油,中国加油'
if '武' in str:
print('存在')
else:
print('不存在')
2\判断最大值,最小值 9>8>7 字符表 元素周期表
max(str)
min(str)
3\字符串的判断
str='ABC'
str.isupper()
str.islower()
str.isalpha()
str.isalnum()
str.isdigit()
str.istitle()
使用性比较高的两种:
startwith(字符串) 是否指定字符开始
endwith(字符串) 是否指定字符结束
str.index('加',9)
lower()
upper()
title()
swapcase()
capitalize()
strip(占位符)
lstrip(占位符)
rstrip(占位符)
ljust(长度,占位符)
rjust(长度,占位符)
center(长度,占位符)
partition(字符串)
rpartition(字符串)
split(字符,切割数)
splitlines(字符串)
join(字符串)
+
str1 = 'hello python,hello world'
print(str1.partition('o'))
print(str1.rpartition('o'))
print(str1.split('o'))
print(str1.split('o', 3))
print(str1.split('o', 4))
str2 = '❥'
print(str1+str2)
print(str2.join('god'))

find(字符串,开始索引,结束索引) 查询
rfind(字符串,开始索引,结束索引) 右侧索引
index(字符串,开始索引,结束索引) 查询
rindex(字符串,开始索引,结束索引) 右侧查询
replace(原字符,新字符,替换数量) 替换
expandtabs() 替换空格
str = 'hello python,hello world'
print(str.index('o'))
print(str.find('o'))