Find specific characters in a Python string

Asked 2 years ago, Updated 2 years ago, 95 views

I wonder how to find a specific string in Python.

Actually, you can just do the string.find ("the string to find"), but

I'd like to do a right-to-left examination, not a left-to-right examination What should I do in this case

python find

2022-09-22 18:01

2 Answers

string.rfind" ("String to Find")

The rfind method allows you to examine from the right.


2022-09-22 18:01

How about this one?

string[::-1].find("string"[::-1])


2022-09-22 18:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.