作业二
字符串 s = ‘this is a book’ 1.请将字符串里的book替换成apple ‘
‘2.请用程序判断该字符串是否以this开头 ‘
‘3.请用程序判断该字符串是否以apple结尾 ‘
‘4.如字符串的末尾有一个@,请将其删除st = 'this is a book'print(st.replace('book','apple'))st_input =input('请输入:')if st_input.startswith('this'):print('是this开头的')elif st_input.endswith('apple'):print('是apple结尾的')elif st_input.strip('@'):st_input.replace('@','')
作业三
将列表 li [2, 5, 6, 4, 9, 10, 23]
1. 降序输出
2. 降序排序后利用切片输出23, 9, 5,2li = [2, 5, 6, 4, 9, 10, 23]li.reverse()print(li)print(li[::2])
作业四
st = input('请输入:')if len(st) > 3 and not st.endswith('ing'):print(st+'ing')elif st.endswith('ing'):print(st+'ly')elif len(st) < 3:print(st)
�
