About 7,050,000 results
Open links in new tab
  1. How do I get a substring of a string in Python? - Stack Overflow

    Aug 31, 2016 · @gimel: Actually, [:] on an immutable type doesn't make a copy at all. While mysequence[:] is mostly harmless when mysequence is an immutable type like str, tuple, …

  2. python - How to substring a string? - Stack Overflow

    Apr 18, 2017 · Extracting substrings: Strings in Python can be subscripted just like an array: s[4] = 'a'. Like in IDL, indices can be specified with slice notation i.e., two indices separated by a …

  3. python - How to extract the substring between two markers

    Jan 12, 2011 · I.e. you need to block parenthesis with slash \ sign. Though it is a problem about more regular expressions that Python. Also, in some cases you may see 'r' symbols before …

  4. Does Python have a string 'contains' substring method?

    Aug 9, 2010 · You may have to handle the exception or -1 cases, and if they return 0 (because they found the substring at the beginning) the boolean interpretation is False instead of True. If …

  5. python - How to find all occurrences of a substring? - Stack Overflow

    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 …

  6. How would I get everything before a : in a string Python

    Feb 14, 2019 · I have benchmarked these various technics under Python 3.9.13 (Jupyter Notebook). TLDR. When I know that c is in s, I would use partition for small strings and index …

  7. python - How do you extract substring after a pattern - Stack …

    Jul 24, 2020 · I don't think you need to use regex since you simply want to extract the substring after the first appearance of a specific sequence of characters. String.index() method returns …

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

    Jul 4, 2021 · You can get the substring by just mentioning the start and end characters/indices. For example: import substring s = substring.substringByChar("abcdefghijklmnop", …

  9. How to get the position of a character in Python?

    Feb 19, 2010 · Most methods I found refer to finding the first substring in a string. To find all the substrings, you need to work around. For example: Define the string. vars = …

  10. python - Find index of last occurrence of a substring in a string ...

    Apr 5, 2020 · Python String rindex() Method. Description Python string method rindex() returns the last index where the substring str is found, or raises an exception if no such index exists, …

Refresh