Quantcast
Viewing latest article 6
Browse Latest Browse All 4912

Python • Python string find index

I am attempting to identify the index for the pipe symbols in the given string. For some reason the function keeps returning the index to the first instance only. Consider below:

Code:

chr2 = "Some Text | More Text text | still more text | last text"index0 = chr2.find("|")index1 = chr2.find("|", index0)index2 = chr2.find("|", index1)index3 = chr2.find("last")
results in:

Index0 = 10
index1 = 10
index2 = 10
index3 = 47

index1 and index2 were intended to return the index to the second and third pipe charters ( "| ')

What did i do wrong?

Statistics: Posted by ras_oscar — Wed Apr 16, 2025 10:38 pm



Viewing latest article 6
Browse Latest Browse All 4912

Trending Articles