7-7 sdut-输出字母在字符串中位置索引

知识点:

逆序遍历range:只需要[::-1]即可
(从头到尾切片,步长设置为-1)

代码

s=input()
a,b=input().split()
for i in range(len(s))[::-1]:
    if s[i]==a or s[i]==b:
        print("{} {}".format(i,s[i]))
posted @ 2022-05-29 09:24  kingwzun  阅读(30)  评论(0编辑  收藏  举报