Sobes.tech
Junior — Middle

Which built-in method in Python allows you to get an element by its position in an iterable sequence?

sobes.tech AI

Answer from AI

In Python, to get an element by its position in an iterable sequence, the indexing operator [] is used. For example, to get the element with index i from a list lst, you write lst[i].

Example:

lst = ['a', 'b', 'c', 'd']
print(lst[2])  # Will output 'c'

If dealing with a more general iterable object that does not support direct indexing (for example, a generator), you can use the itertools.islice function or convert it to a list.