About 17,100,000 results
Open links in new tab
  1. How to find index of an exact word in a string in Python

    Aug 15, 2016 · index = string.center(len(string) + 2, ' ').find(word.center(len(word) + 2, ' ')) Here both the string and the word are right and left padded with blanks as to capture the full word in any position of the string.

  2. Python String index() Method - W3Schools

    The index() method finds the first occurrence of the specified value. The index() method raises an exception if the value is not found. The index() method is almost the same as the find() method, the only difference is that the find() method returns …

  3. How to get the whole word starting at an index in a string in Python

    Apr 27, 2018 · split the string at your search phrase. Then take the "boundary" words from the resulting sentence fragments: before = frag_list[frag ].split()[-1] # Last word of left fragment. after = frag_list[frag+1].split()[0 ] # First word of right fragment. # Do what you need to with the two words. Does that help?

  4. python - Slicing a word in half - Stack Overflow

    Oct 13, 2020 · half1 = word[:len(word)+(len(word)%2==1)] half2 = word[len(word)+(len(word)%2==1):] print (half2+half1)

  5. How to Index and Slice Strings in Python? - GeeksforGeeks

    Dec 31, 2024 · In this article, we will discuss how to access an index in for loop using Python. Here, we will be using 4 different methods of accessing the index of a list using for loop, including approaches to finding index for strings, lists, etc.

  6. Python - Slicing Strings - W3Schools

    You can return a range of characters by using the slice syntax. Specify the start index and the end index, separated by a colon, to return a part of the string. Get the characters from position 2 to position 5 (not included): b = "Hello, World!" Note: The first character has index 0.

    Missing:

    • Word

    Must include:

  7. Python program to find start and end indices of all Words in a …

    May 16, 2023 · Find the starting index of the word using the index() method and store it in a variable start. Find the ending index of the word by adding the length of the word minus 1 to the starting index and store it in a variable end.

  8. Python String `index()` Method: A Comprehensive Guide

    Apr 6, 2025 · The `index()` method is a powerful tool when working with strings, allowing you to find the position of a substring within a larger string. Understanding how to use `index()` effectively can significantly simplify text manipulation tasks, such as parsing data, searching for specific words, or validating input.

  9. Python – Word starting at Index - GeeksforGeeks

    Sep 5, 2022 · To get index of a substring within a Python string can be done using several methods such as str.find(), str.index(), and even regular expressions. Each approach has its own use case depending on the requirements.

  10. How To Index and Slice Strings in Python 3 - DigitalOcean

    Dec 15, 2021 · By referencing index numbers, we can isolate one of the characters in a string. We do this by putting the index numbers in square brackets. Let’s declare a string, print it, and call the index number in square brackets:

  11. Some results have been removed