Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
••••••••
Sicherheitslücken (CVE)CVE-2025-65823 | Meatmeet App on Android hard-coded credentials(29.09.2026 um 03:42 Uhr)
••••••••••
Sicherheitslücken (CVE)CVE-2025-65823 | Meatmeet App on Android hard-coded credentials(29.09.2026 um 03:42 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

find in Python

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

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Buy Me a Coffee☕



*Memos:





str.find() and bytes.find() or bytearray.find() can find the 1st substring and byte substring respectively, searching from the left to the right 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.find() or bytes-like object for bytes.find() and bytearray.find()):


    • 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.find('pe')) # 3
print(v.find('pe', None, None)) # 3
print(v.find('PE')) # -1
print(v.find('pe', 3)) # 3
print(v.find('pe', 4)) # 7
print(v.find('pe', 7)) # 7
print(v.find('pe', 8)) # -1
print(v.find('pe', 0, 4)) # -1
print(v.find('pe', 0, 5)) # 3
print(v.find('pe', 7, 12)) # 7
print(v.find('pe', 8, 12)) # -1

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









v = ''

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









<Byte String(UTF-8)>:






bytes() & bytearray():






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

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

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









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

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


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten find in Python

Thematisch verwandte Begriffe: find, 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
ZERO-DAY CVE-2026-102265 | PyJWT is a Python implementation of JSON Web Token standards. From 2.13…
Advisory →
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