Which Python built-in function can be used to iterate over a sequence while also obtaining the index of the current item?
- enumerate()
- for_each()
- index()
- iterate()
The enumerate() function in Python is used to iterate over a sequence (like a list or tuple) while also obtaining the index of the current item. It returns pairs of index and value, making it helpful for certain looping scenarios.
Loading...
Related Quiz
- When you want a variable to be available both inside and outside a function, you declare it as a _______ variable.
- When debugging, the ____ command in Pdb is used to print the value of an expression.
- How would you optimize the performance of a RESTful API that serves large datasets?
- The ____ method returns the number of occurrences of a substring in the given string.
- Which decorator in Python is commonly used to define a method as a class property getter?