Use with AIfor i in range(15):
    print i #will print out 0..14

for i in range(1, 15):
    print i # will print out 1..14


for i in range (a, b, s):
    print i # will print a..b-1 counting by s. interestingly if while counting by the step 's' you exceed b, it will stop at the last 'reachable' number, example

for i in range(1, 10, 3):
    print i

> 1
> 4
> 7

List Splicing:

Use with AIa = "hello" # there are 5 characters, so the characters are accessible on indexes 0..4

a[1] = 'e'
a[1:2] = 'e' # because the number after the colon is not reached.

a[x:y] = all characters starting from the character AT index 'x' and ending at the character which is before 'y'

a[x:] = all characters starting from x and to the end of the string

In the future, if you ever wonder what the behavior of python is like, you can try it out in the python shell. just type python in the terminal and you can enter any lines you want (though this is mostly convenient for one-liners rather than scripts).

Answer from Jeremy Fisher on Stack Overflow
🌐
W3Schools
w3schools.com › Python › python_lists_access.asp
Python - Access List Items
List items are indexed and you can access them by referring to the index number.
Discussions

Is range(len(list)) ever Pythonic?
On a related note, you should never name your variable list. More on reddit.com
🌐 r/learnpython
79
83
September 9, 2022
python - how to extract a range of index from a list - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
Droping data with range of negitive indexes
I’m working with list and list of list. I need to be able to address the data from both ways (right to left and left to right). This is needed when you have a list of lists AND need to address the last ‘sub’ list of the list of lists. Just groups of data. More on discuss.python.org
🌐 discuss.python.org
4
0
January 14, 2023
python - Why can't a range object be used to index a list? - Stack Overflow
In Python 3.9, it is not possible to use a range object to index a list. Indeed running the following code, the second print will return an error stating "TypeError: list indices must be integ... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

What is the "list index out of range" error?

The "list index out of range" error occurs when you try to access an index that is outside the range of valid indices for a list. For example, if a list has 5 elements, the valid indices are 0 to 4. If you try to access an index greater than or equal to 5, you will get this error.

To avoid the "list index out of range" error, you should make sure that the index you are trying to access is within the range of valid indices for the list. You can use the len() function to get the length of a list and check if an index is within the range of valid indices.

🌐
datacamp.com
datacamp.com › home › tutorials › python › python list index() method explained with examples
Python List index() Method Explained with Examples | DataCamp
What is the "list indices must be integers" error?

The "list indices must be integers" error occurs when you try to use a non-integer value as a list index. For example, if you try to use a floating-point number or a string as a list index, you will get this error.

To avoid the "list indices must be integers" error, you should make sure that you are using an integer value as a list index. If you need to use a non-integer value as an index, you can convert it to an integer using the int() function.

🌐
datacamp.com
datacamp.com › home › tutorials › python › python list index() method explained with examples
Python List index() Method Explained with Examples | DataCamp
How is index() different from find()?

The find() method is used with strings and returns -1 instead of raising an error when the value is not found. Lists do not have a find() method.

text = "hello"
print(text.find('e'))  # Output: 1
print(text.find('z'))  # Output: -1
🌐
datacamp.com
datacamp.com › home › tutorials › python › python list index() method explained with examples
Python List index() Method Explained with Examples | DataCamp
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-range.html
Python range() - Stanford Computer Science
>>> list(range(2)) [0, 1] >>> list(range(1)) [0] >>> list(range(0)) # n <= 0, no numbers [] >>> list(range(-42)) [] Probably the second most common problem is to go through the standard index numbers, but in reverse order. The reversed() function takes in a linear collection and returns a reversed form of it. This works nicely with range() to go over the regular numbers in reverse order: >>> s = 'Python' >>> len(s) 6 >>> for i in reversed(range(len(s))): ...
🌐
Railsware
railsware.com › home › engineering › indexing and slicing for lists, tuples, strings, other sequential types in python
Python Indexing and Slicing for Lists, Tuples, Strings, other Sequential Types | Railsware Blog
September 28, 2026 - Indexing (list[i]) accesses or modifies a single element by its position. Slicing (list[start:stop:step]) extracts, replaces, or deletes a range of elements and returns a new list rather than a single value.
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.15.2 documentation
3 weeks ago - We saw that lists and strings have many common properties, such as indexing and slicing operations. They are two examples of sequence data types (see Sequence Types — list, tuple, range). Since Python is an evolving language, other sequence data types may be added.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-index
Python List index() - Find Index of Item - GeeksforGeeks
Example 3: In this example, index() is used with a list containing tuple elements. ... Explanation: a.index(("Lucas", 22)) searches for the exact tuple ("Lucas", 22) and tuple is found at index 1.
Published: July 17, 2026
🌐
freeCodeCamp
freecodecamp.org › news › python-range-function-explained-with-code-examples
Python range() Function – Explained with Code Examples
October 6, 2021 - If you remember, all iterables in Python follow zero-indexing. This is why it's convenient to use range() to loop through iterables. An iterable of length len has 0, 1, 2, ..., len-1 as the valid indices. So to traverse any iterable, all you need to do is to set the stop value to be equal to len. The sequence you'll get – 0, 1, 2, ..., len-1 – is the sequence of valid indices. ▶ Let's take a more helpful example. You have a list my_list.
🌐
Purple Frog Systems
purplefrogsystems.com › home › python lists – what do i need to know?
Python Lists – What do I need to know? - Purple Frog Systems
July 22, 2025 - Items can be found and counted ... the next element in the list to a loop variable. The range() and len() functions can be used together to loop through a list by index....
🌐
DataCamp
datacamp.com › home › tutorials › python › python list index() method explained with examples
Python List index() Method Explained with Examples | DataCamp
March 28, 2025 - So the syntax is: list_name.index(element, start, stop). Here the start and stop values are optional. In fact, only use it when entirely sure about the range; otherwise, you will get a ValueError, as shown below.
🌐
Mimo
mimo.org › glossary › python › range-function
Python range(): start, stop and step in Loops
Using the range() function to generate list indices can lead to IndexError-type errors. To prevent such errors, you can create for loops with the list to iterate over instead of a range of indices.
🌐
freeCodeCamp
freecodecamp.org › news › list-index-out-of-range-python-error-message-solved
List Index Out of Range – Python Error Message Solved
January 20, 2022 - You'll get the Indexerror: list index out of range error when iterating through a list and trying to access an item that doesn't exist. One common instance where this can occur is when you use the wrong integer in Python's range() function.
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › user_guide › indexing.html
Indexing and selecting data — pandas 3.1.1 documentation
The Python and NumPy indexing operators [] and attribute operator . provide quick and easy access to pandas data structures across a wide range of use cases. This makes interactive work intuitive, as there’s little new to learn if you already know how to deal with Python dictionaries and ...
🌐
Python.org
discuss.python.org › python help
Droping data with range of negitive indexes - Python Help - Discussions on Python.org
January 14, 2023 - I’m working with list and list of list. I need to be able to address the data from both ways (right to left and left to right). This is needed when you have a list of lists AND need to address the last ‘sub’ list of the …
🌐
W3Schools
w3schools.com › python › ref_list_index.asp
Python List index() Method
Remove List Duplicates Reverse ... Plan Python Interview Q&A Python Training ... The index() method returns the position at the first occurrence of the specified value....
🌐
GeeksforGeeks
geeksforgeeks.org › python-list-slicing
Python List Slicing - GeeksforGeeks
Let’s see how to use list slicing in Python with the examples below. To retrieve all items from a list, we can use slicing without specifying any parameters. ... Explanation: Using [:] & [::] without specifying any start, end, or step returns all elements of the list. To get all the items from a specific position to the end of the list, we can specify the start index and leave the end blank.
Published: March 8, 2025
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-lists
Python Lists - GeeksforGeeks
Python uses zero-based indexing, meaning a[0] represents the first element. Negative indexing is also supported, where -1 accesses the last element. ... Since lists are mutable, elements can be updated by assigning new values using their index.
Published: September 19, 2026
🌐
YouTube
youtube.com › watch
Python Range Explained | Python Ranges vs Lists - YouTube
💻 *Get my Source Codes and support the channel* ❤️: https://www.buymeacoffee.com/fabiomusanni/extras⬇️ *LEARN ON THE BEST LEARNING PLATFORMS (LINKS BELOW)* ...
Published: September 5, 2022