|
发表于 2020-12-17 21:30:00
|
显示全部楼层
本楼为最佳答案
给你加了几行注释,应该是清楚了
看好了:
- str1 ='aASDASDdsfhsado'
- list1 = []
- for each in str1: #遍历字符串,将字符全部加入list1列表
- list1.append(each)
- print(list1) #输出列表
- for each1 in list1:
-
- if each1.islower(): #遍历列表取其中小写字母
- print(each1,'是小写字符,它的索引减一的字符为:')
- b1 = list1[(list1.index(each1)-1)]
- print(b1)
-
复制代码
输出结果为:
- ['a', 'A', 'S', 'D', 'A', 'S', 'D', 'd', 's', 'f', 'h', 's', 'a', 'd', 'o']
- a 是小写字符,它的索引减一的字符为:
- o
- d 是小写字符,它的索引减一的字符为:
- D
- s 是小写字符,它的索引减一的字符为:
- d
- f 是小写字符,它的索引减一的字符为:
- s
- h 是小写字符,它的索引减一的字符为:
- f
- s 是小写字符,它的索引减一的字符为:
- d
- a 是小写字符,它的索引减一的字符为:
- o
- d 是小写字符,它的索引减一的字符为:
- D
- o 是小写字符,它的索引减一的字符为:
- d
复制代码 |
|