Sobes.tech
Junior — Middle

Is it possible to get an element from a range of numbers using index access in Python?

sobes.tech AI

Answer from AI

In Python, an object of type range supports indexing, so you can access an element from the range by its index.

Example:

r = range(10, 20)
print(r[0])  # Outputs 10
print(r[5])  # Outputs 15

If the index is out of the range, an IndexError will be raised.

Therefore, yes, you can access an element of a range by its index, just like a list element.

Is it possible to get an element from a range of… - sobes.tech