About 253,000 results
Open links in new tab
  1. string - How to get the position of a character in Python ... - Stack ...

    Feb 19, 2010 · Python has a in-built string method that does the work: index(). string.index(value, start, end) Where: Value: (Required) The value to search for. start: (Optional) Where to start …

  2. python - How to check a string for specific characters ... - Stack …

    This is very misleading. The performance difference is due to the hit in setting up the generator expression for any(). Increasing the string size to 2000 does almost nothing since it will almost …

  3. python - How to get a string after a specific substring ... - Stack ...

    Jul 4, 2021 · Note that this produces an empty string if the delimiter is missing: >>> my_string.partition("Monty")[2] # delimiter missing '' If you want to have the original string, then …

  4. python - Find the nth occurrence of substring in a string - Stack …

    This will find the second occurrence of substring in string. def find_2nd(string, substring): return string.find(substring, string.find(substring) + 1) Edit: I haven't thought much about the …

  5. python - How to get char from string by index? - Stack Overflow

    Jan 13, 2012 · Previous answers cover about ASCII character at a certain index. It is a little bit troublesome to get a Unicode character at a certain index in Python 2. E.g., with s = '한국中国 …

  6. python - How to find all occurrences of a substring ... - Stack …

    Python has string.find() and string.rfind() to get the index of a substring in a string. I'm wondering whether there is something like string.find_all() which can return all found indexes (not only the …

  7. python - Find all the occurrences of a character in a string - Stack ...

    Oct 22, 2012 · text.find returns an integer (the index at which the desired string is found), so you can run for loop over it. I suggest: def findSectionOffsets(text): indexes = [] startposition = 0 …

  8. python - How to get the first character of a string ... - Stack Overflow

    Dec 19, 2018 · in this case minus one is equal to the index of the last character which is 3. so firstname[0:-1] will return "ann". in your case it should be changed to firstname[0]. str in the …

  9. python - Finding All Positions Of A Character In A String - Stack …

    Sep 22, 2018 · I'm trying to find all the index numbers of a character in a python string using a very basic skill set. For example if I have the string "Apples are totally awesome" and I want to …

  10. Check if a word is in a string in Python - Stack Overflow

    If you want to find indices of ALL INSTANCES of a word or character inside a string use below codes: # This example finds indices of all instances of the character: '#' x = "1)#welcome #to …