![](/img/trans.png)
[英]How to find the index of the last character of a substring in python
[英]how to find previous character and index for character
您能幫我這個忙嗎,所以我想要的是,我輸入文本“ hello”,我得到幾秒鍾一一索引的字符
對於變體2,而不是:
if lastElement == (ch - 1):
關於什么:
if lastElement == text[elmt-1]
這將產生所需的輸出:
target = 'ol'
after = 'l'
before = 'e'
text = 'hello'
for elmt, ch in enumerate(text):
print(ch, elmt)
if ch in target:
print('was {}'.format(ch.upper()))
if ch == after:
if last in before:
print('before this {} was {}\n'.format(ch.upper(), last.upper()))
else:
print('before was other character not {}\n'.format(before.upper()))
last = ch
輸出:
h 0
e 1
l 2
was L
before this L was E
l 3
was L
before was other character not E
o 4
was O
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.