Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
••
Linux Tipps & HardeningCPU Graph, a scrubbable adjustable CPU monitor(30.09.2026 um 21:25 Uhr)
••
Linux Tipps & HardeningLinux 7.2.2 on iPhone XS? First boot!(30.09.2026 um 22:12 Uhr)
••
Linux Tipps & HardeningMinecraft Dungeons 2 fix for linux(01.10.2026 um 00:49 Uhr)
••
Linux Tipps & HardeningEuropean Citizens' Initiative(01.10.2026 um 04:15 Uhr)
••••
Linux Tipps & HardeningCPU Graph, a scrubbable adjustable CPU monitor(30.09.2026 um 21:25 Uhr)
••
Linux Tipps & HardeningLinux 7.2.2 on iPhone XS? First boot!(30.09.2026 um 22:12 Uhr)
••
Linux Tipps & HardeningMinecraft Dungeons 2 fix for linux(01.10.2026 um 00:49 Uhr)
••
Linux Tipps & HardeningEuropean Citizens' Initiative(01.10.2026 um 04:15 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

rfind in Python

Buy Me a Coffee☕ *Memos: My post explains count() with a string and byte string. My post explains find() with a string and byte string. My post explains i…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

Buy Me a Coffee☕



*Memos:





str.rfind() and bytes.rfind or bytearray.rfind() can find the 1st substring and byte substring respectively, searching from the right to the left to return the index (without error even if the substring and byte substring respectively aren't found) as shown below:



*Memos:




  • The 1st argument is sub(Required-Type:str for str.rfind() or bytes-like object for bytes.rfind() and bytearray.rfind()):


    • It's the substring or byte substring of zero or more characters.

    • Don't use sub=.






  • The 2nd argument is start(Optional-Type:int or NoneType):


    • It's a start index.

    • If it's not set or None, 0 is set.

    • Don't use start.






  • The 3rd argument is end(Optional-Type:int or NoneType):


    • It's an end index.

    • If it's not set or None, the length + 1 is set.

    • Don't use end.







  • -1 is returned if the substring or byte substring isn't found.







<String>:






v = 'grapes peach'

print(v.rfind('pe')) # 7
print(v.rfind('pe', None, None)) # 7
print(v.rfind('PE')) # -1
print(v.rfind('pe', 3)) # 7
print(v.rfind('pe', 4)) # 7
print(v.rfind('pe', 7)) # 7
print(v.rfind('pe', 8)) # -1
print(v.rfind('pe', 0, 4)) # -1
print(v.rfind('pe', 0, 5)) # 3
print(v.rfind('pe', 7, 12)) # 7
print(v.rfind('pe', 8, 12)) # -1

print(v.rfind('')) # 12
print(v.rfind('g', 0, 1)) # 0
print(v.rfind('h', 11, 12)) # 11
print(v.rfind('abc')) # -1









v = ''

print(v.rfind('')) # 0









<Byte String(UTF-8)>:






bytes() & bytearray():






v = 'grapes peach'.encode()
v = b'grapes peach'
v = bytearray('grapes peach'.encode())

print(v.rfind('pe'.encode())) # 7
print(v.rfind(b'pe')) # 7
print(v.rfind(bytearray('pe'.encode()))) # 7
print(v.rfind('pe'.encode(), None, None)) # 7
print(v.rfind(b'pe', None, None)) # 7
print(v.rfind(bytearray('pe'.encode()), None, None)) # 7
print(v.rfind('PE'.encode())) # -1
print(v.rfind(b'PE')) # -1
print(v.rfind(bytearray('PE'.encode()))) # -1
print(v.rfind('pe'.encode(), 3)) # 7
print(v.rfind(b'pe', 3)) # 7
print(v.rfind(bytearray('pe'.encode()), 3)) # 7
print(v.rfind('pe'.encode(), 4)) # 7
print(v.rfind(b'pe', 4)) # 7
print(v.rfind(bytearray('pe'.encode()), 4)) # 7
print(v.rfind('pe'.encode(), 7)) # 7
print(v.rfind(b'pe', 7)) # 7
print(v.rfind(bytearray('pe'.encode()), 7)) # 7
print(v.rfind('pe'.encode(), 8)) # -1
print(v.rfind(b'pe', 8)) # -1
print(v.rfind(bytearray('pe'.encode()), 8)) # -1
print(v.rfind('pe'.encode(), 0, 4)) # -1
print(v.rfind(b'pe', 0, 4)) # -1
print(v.rfind(bytearray('pe'.encode()), 0, 4)) # -1
print(v.rfind('pe'.encode(), 0, 5)) # 3
print(v.rfind(b'pe', 0, 5)) # 3
print(v.rfind(bytearray('pe'.encode()), 0, 5)) # 3
print(v.rfind('pe'.encode(), 7, 12)) # 7
print(v.rfind(b'pe', 7, 12)) # 7
print(v.rfind(bytearray('pe'.encode()), 7, 12)) # 7
print(v.rfind('pe'.encode(), 8, 12)) # -1
print(v.rfind(b'pe', 8, 12)) # -1
print(v.rfind(bytearray('pe'.encode()), 8, 12)) # -1

print(v.rfind(''.encode())) # 12
print(v.rfind(b'')) # 12
print(v.rfind(bytearray(''.encode()))) # 12
print(v.rfind('g'.encode(), 0, 1)) # 0
print(v.rfind(b'g', 0, 1)) # 0
print(v.rfind(bytearray('g'.encode()))) # 0
print(v.rfind('h'.encode(), 11, 12)) # 11
print(v.rfind(b'h', 11, 12)) # 11
print(v.rfind(bytearray('h'.encode()), 11, 12)) # 11
print(v.rfind('abc'.encode())) # -1
print(v.rfind(b'abc')) # -1
print(v.rfind(bytearray('abc'.encode()))) # -1









v = ''.encode()
v = b''
v = bytearray(''.encode())

print(v.rfind(''.encode())) # 0
print(v.rfind(b'')) # 0
print(v.rfind(bytearray(''.encode()))) # 0


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten rfind in Python

Thematisch verwandte Begriffe: rfind, Python · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag