day2-字符串修饰符练习

str1 = '''Whatever pleasure Myra may have shown at the 
commencement of this speech gave 0 way 0 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在字符串当中出现的次数
str_=str1.splitlines()
print(str1.count('is'))

# 第一行:查找Myra第一个出现的位置
str_1=str_[0]
print(str_1.index('Myra'))

# 第二行:将第二行分割成'commencement of this speech gave ','way',' to a mutinous frown '
str_2=str_[1]
print(str_2.split('0'))

# 第三行:将mind替换成branie,将p和o 替换成a和z,指定translates方法
str_3=str_[2]
print(str_3.replace('mind','branie'))
str_4='as its later aurazrt aenetrated her mind. Had she nzt had his '
str_5=str.maketrans(str_3,str_4)
str_6='as its later purport penetrated her mind. Had she not had his  '
jg=str_6.translate(str_5)
print(jg)

# 第四行:将promise提取出来,将第四行反向打印输出
str_7=str_[3]
print(str_7[9:16])
print(str_7[::-1])

# 第五行:判断字符串是否都是字母组成,判断每个单词首字母都是大写
str_8=str_[4]
print(str_8.isalpha())
print(str_8.isupper())

;