Python Programming - Loops - Discussion
Discussion Forum : Loops - General Questions (Q.No. 5)
5.
What does the
enumerate
function do when used in a for
loop?Answer: Option
Explanation:
The enumerate()
function adds an index to each element in an iterable, returning pairs of index and element.
my_list = ['apple', 'banana', 'orange', 'grape']
for index, value in enumerate(my_list):
print(f"Index: {index}, Value: {value}")
Output:
Index: 0, Value: apple
Index: 1, Value: banana
Index: 2, Value: orange
Index: 3, Value: grape
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers