In Python, you can access the index value in a for
loop using the built-in enumerate()
function. This function returns both the index and the value as you iterate over an iterable, like a list. Here’s an example:
The enumerate()
function takes two arguments: the iterable and an optional start value (default is 0). It returns a tuple, where the first element is the index and the second is the corresponding value