homework of the second day

# 作业:代码两遍(注释加上)
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 
'''
# #全文
cou =str1.count('is')
print(cou)
# #第一行
fir = str1.find('Myra')
print(fir)
# #第二行
sec = str1.splitlines()
result1=sec[1]
print(result1[:33])
print(result1[33:36])
print(result1[36:])
#第三行
intab = 'po'
outab = 'az'
result2=sec[2]
thr = result2.replace('mind','branie')
print(thr)
str_tran =str.maketrans(intab,outab)
answer = thr.translate(str_tran)
print(answer)
#第四行
four = sec[3]
print(four[9:16])
print(four[::-1])
four1 = four.isalpha()#是否都是字母组成
print(four1)
four2 = four.istitle()#首字母是否大写
print(four2)
#第五行
five = sec[4]
five1 = five.isalpha()
print(five1)
five2 = five.istitle()
print(five2)
# 全文:查找is在字符串当中出现的次数
# 第一行:查找Myra第一个出现的位置
# 第二行:将第二行分割成'commencement of this speech gave ',
# 'way',' to a mutinous frown '
# 第三行:将mind替换成branie,将p和o 替换成a和z,指定translates方法
# 第四行:将promise提取出来,将第四行反向打印输出
# 四五行:判断字符串是否都是字母组成,判断每个单词首字母都是大写

猜你喜欢

转载自blog.csdn.net/weixin_44367451/article/details/85716404