GeeksforGeeks
geeksforgeeks.org › python › python-list-index
Python List index() - Find Index of Item - GeeksforGeeks
Example: In this example, index() is used to find the position of an element in a list. ... Explanation: a.index("dog") searches for "dog" in the list and element is found at index 1, so 1 is returned.
Published: July 17, 2026
Programiz
programiz.com › python-programming › methods › list › index
Python List index() (with Code Visualization)
models = ['Claude', 'ChatGPT', 'Gemini', 'ChatGPT'] # Search 'ChatGPT' from start to end index = models.index('ChatGPT') print(index) # Output: 1 # Search 'ChatGPT' from index 2 to end index = models.index('ChatGPT', 2) print(index) # Output: 3 # Search 'ChatGPT' from index 2 to index 3 (exclusive) index = models.index('ChatGPT', 2, 3) print(index) # ValueError: 'ChatGPT' is not in list · Note: Python also supports negative indexing and you can use negative start and end indices with index().
Embarrassingly, i don't understand how list indexing works
Let us step back a little. Before understanding your example, try to grok the example below for i in range(0, 3): print(i) which results in: 0 1 2 And the example below my_list = [42, 6, 2024] for i in range(0, 3): print(i, my_list[i]) Which results in: 0 42 1 6 2 2024 Are those clear to ya? Thanks! More on reddit.com
What's the meaning and purpose of [-1] in this function?
Well, let's break it down! words = [[str[0]]] This is written somewhat strangely, but basically it is setting the words variable to a list containing the first character of the string (note: this code should not use str as a variable name as this is also a type). for c in str[1:]: This for loop is going over the rest of the string character by character. This is called a slice, and essentially it cuts the list into index values. For example, if you had a list [1, 2, 3, 4, 5] and you indexed it with [2:3], the list you'd get back is [3, 4]. This is because you are slicing from index 2 (the third item since indexes start at 0) to index 3 (the 4th item). If you did [2:] instead, your list would be [3, 4, 5], as the empty value means "to the end of the list." If you reversed it with [:2] you'd instead get a list of [1, 2] because you are slicing from 0 (start) to 2. Note that [:2] and [0:2] are functionally the same. In the next section, you have words[-1][-1]. An index of [-1] means "the last element (length - 1). Any time you have a negative index in Python, it means "that many from the length." NOTE: a slice at the end must be blank if you want the last character. If you did [2:] and [2:-1] you'd get different values...in this case [3, 4, 5] and [3, 4] respectively. So what does the words[-1][-1] actually do? Well, remember that words is a list of characters. So you are looking at the last string and last letter of that string, then checking if it is lower case. The if also checks if the next letter is upper case. If it is, we append a new list of characters to the end of the words list. If not, we are instead appending the current character to the current list. This is repeated for the whole string. This list of lists is then converted into a list of individual strings by combining the internal lists into strings instead of a list of characters. You can tell what's going on if you put a print statement before the return. If I had a string, say, testWordOutput, the list before the returning list comprehension looks like this: [['t', 'e', 's', 't'], ['W', 'o', 'r', 'd'], ['O', 'u', 't', 'p', 'u', 't']]. This is actually a somewhat overcomplicated way to do this. You can skip the entire part where you create the internal lists, for example this code: def split_camel_case(original): if not original: # Early return for empty string return [] words = [original[0]] # Start with the first character for char in original[1:]: # If the current character is uppercase and # the previous character is lowercase, # start a new word if char.isupper() and words[-1][-1].islower(): words.append(char) else: # Otherwise, append the current character to the last word words[-1] += char return words This code does the exact same thing but is perhaps a bit more clear in how it works. It still has many of the same elements (the basic concept wasn't wrong) but removes the need for a list comprehension. Hopefully that makes sense, please let me know if you have questions. More on reddit.com
Looking for a way to add an element into a list without using insert()
More time efficient than insert? why are you looking for such a thing? also why do you think such a thing exists? More on reddit.com
Why is the index -1 always denoted as the last element of a list in python?
You can count backwards from the end like this. -1 is the last item, and -2 is the second to last item, etc. More on reddit.com
16:51
How to Access Lists in Python (Indexing & Slicing Explained) | ...
Accessing Items in a List using Indexing in Python - YouTube
13:51
Python Lists for Beginners - List Indexing, List Methods, List ...
05:38
Write Python Program to Concatenate Two Lists Index Wise | Python ...
08:03
Python Program to Find the Minimum Element from a List of Element ...
04:04
Python List Method - index() - YouTube
DataCamp
datacamp.com › tutorial › python-list-index
Python List index() Method Explained with Examples | DataCamp
March 28, 2025 - If the value is not found in the sequence, the function raises a ValueError. For example, if we have a list [1, 2, 3, 4, 5], we can find the index of the value 3 by calling list.index(3), which will return the value 2 (since 3 is the third element in the list, and indexing starts at 0).
W3Schools
w3schools.com › python › ref_list_index.asp
Python List index() Method
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The index() method returns the position at the first occurrence of the specified value.
ReqBin
reqbin.com › code › python › h54arbqc › python-list-index-example
How do I find the index of an element in a Python list?
To find the index of an element in a Python list, you can use the list.index(element, start, end) method.
Guru99
guru99.com › home › python › python list index() with example
Python List index() with Example
July 11, 2026 - Enumerate() function is a built-in function available with Python. You can make use of enumerate to get all the indexes of the element in a list. It takes input as an iterable object (i.e., an object that can be looped), and the output is an object with a counter to each item. The following example shows how to make use of enumerate on a list to get all the indexes for a given element.
freeCodeCamp
freecodecamp.org › news › indices-of-a-list-in-python-list-indexof-equivalent
Indices of a List in Python – List IndexOf() Equivalent
April 6, 2023 - herbivores = ["Goat", "Giraffe", "Sheep", "Cattle", "Antelope", "Giraffe" "Rabbit"] index_of_giraffe = herbivores.index("Giraffe") print(index_of_giraffe) # Output: 1 omnivores = ["Pig", "Dogs", "Duck" "Bears" "Ostrich", "Hen", "Warthog", "Bears", "Dogs"] index_of_dogs = omnivores.index("Dogs") print(index_of_dogs) # Output: 1 · As already pointed out, you can use the start and stop parameters to specify where the index() method should start searching for the item and stop searching for it. Let's see how the start parameter works first. In the omnivores list below, let’s search for the position of the second occurrence of Dogs:
W3Schools
w3schools.com › python › python_lists_access.asp
Python - Access List Items
When specifying a range, the return value will be a new list with the specified items. ... thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(thislist[2:5]) Try it Yourself » · Note: The search will start at index 2 (included) and end at index 5 (not included). Remember that the first item has index 0. By leaving out the start value, the range will start at the first item: This example returns the items from the beginning to, but NOT including, "kiwi":
TUHH
www3.tuhh.de › sts › hoou › data-quality-explored › 0-5-3-lists.html
Lists and indexes — Data Quality Explored
This allows you to call each value in a list by its position (called Index) in the list. This is called indexing and it works just like calling values in a string: ... Thus the number 7 is at index 0 of the list x. The number 4.5 is at index 1 and ‘apple’ at index 2.
Programiz
programiz.com › python-programming › examples › index-for-loop
Python Program to Access Index of a List Using for Loop
To understand this example, you should have the knowledge of the following Python programming topics: Python for Loop · Python Lists · Python enumerate() my_list = [21, 44, 35, 11] for index, val in enumerate(my_list): print(index, val) Output · 0 21 1 44 2 35 3 11 ·
freeCodeCamp
freecodecamp.org › news › python-find-in-list-how-to-find-the-index-of-an-item-or-element-in-a-list
Python Find in List – How to Find the Index of an Item or Element in a List
February 24, 2022 - programming_languages = ["JavaScript","Python","Java","Python","C++","Python"] print(programming_languages.index("Python",1,5)) #output #1 · The output still returns only the first instance! Although the start and end parameters provide a range of positions for your search, the return value when using the index() method is still only the first occurence of the item in the list. Let's take the same example that we've used so far.
Roberto Reif
robertoreif.com › blog › 2025 › 7 › 8 › python-lists-index
PYTHON LISTS: Index — Roberto Reif
October 25, 2025 - In Python, when working with lists, you may need to find the index of the first occurrence of a specific element. To do this, use the index method, passing the desired item as an argument. This method returns the index position of the element within the list. What other Python questions do you have
Codecademy
codecademy.com › docs › python › lists › .index()
Python | Lists | .index() | Codecademy
June 11, 2025 - This example demonstrates the fundamental usage of the .index() method to find the position of an element in a simple list: ... The method successfully locates ‘Java’ at index position two and ‘Python’ at index position 0, demonstrating how Python uses zero-based indexing, where the first element is at position 0.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
GeeksforGeeks
geeksforgeeks.org › python › python-accessing-index-and-value-in-list
Accessing index and value in Python list - GeeksforGeeks
July 11, 2025 - a = [1, 4, 5, 6, 7] b = ['a', 'b', 'c', 'd', 'e'] for i, v in zip(range(len(a)), zip(a,b)): print(i, v) ... Explanation: This code uses zip() to pair elements from lists a and b, and then combines it with range(len(a)) to include the index.