Find specific characters in a Python string

Asked 1 years ago, Updated 1 years ago, 85 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.