14.字符串
in 与 not in
name='steven'
result='t' in name
print(result) #True
方括号[]
filename='picture.png'
print(filename[1:8])
顺序输出
[ : ]
[ : : ]
逆序输出
[ : :-1]
[x:y:-1]此时x,y与顺序输出相反
字符串的内建函数
1)字母处理
.upper() # 全部大写
.lower() # 全部小写
.swapcase() # 大小写互换
.capitalize() # 首字母大写,其余小写
.title() # 首字母大写
2)格式化相关
.ljust(width) # 获取固定长度,左对齐,右边不够用空格补齐
.rjust(width) # 获取固定长度,右对齐,左边不够用空格补齐
.center(width) # 获取固定长度,中间对齐,两边不够用空格补齐
.zfill(width) # 获取固定长度,右对齐,左边不足用0补齐
3)字符串搜索相关
.find() # 搜索指定字符串,没有返回-1
.index() # 同上,但是找不到会报错
.rfind() # 从右边开始查找
.count() # 统计指定的字符串出现的次数
find(str,beg=0,end=len(string)
检测str是否包含在字符串中,如果指定范围beg和end,则检查是否包含在指定范围内,如果包含返回开始的索引值,否则返回-1。
s1='index lucy lucky goods'
position=s1.find('R')
print(position