str1 = '''Whatever pleasure Myra may have shown at the
commencement of this speech gave way to a mutinous frown
as its later purport penetrated her mind. Had she not had his
explicit promise that she should not be directly involved in
the handling of these illicit
'''
# 全文:查找is在字符串当中出现的次数
# 第一行:查找Myra第一个出现的位置
# 第二行:将第二行分割成'commencement of this speech gave ',
# 'way',' to a mutinous frown '
# 第三行:将mind替换成branie,将p和o 替换成a和z,指定translates方法
# 第四行:将promise提取出来,将第四行反向打印输出
# 四五行:判断字符串是否都是字母组成,判断每个单词首字母都是大写
print(str1.count('is'))
print(str1.find('Myra'))
a=str1.splitlines()
a1=a[1]
print(a1.partition('way'))
a2=a[2]
a3=a2.replace('mind','branie')
print(a3)
intab='pp'
outtab='az'
b=str.maketrans(intab,outtab)
print(a3.translate(b))
a4=a[3]
print(a4[::-1])
print(a4[9:16])
print(a4.isalpha())
print(a[4].isalpha())
print(a4.istitle())
print(a[4].istitle())
string类型的常用方法
最新推荐文章于 2020-10-19 17:46:18 发布