22.9k views
4 votes
Why is the len () function useful when using a loop to iterate through a stack?​

2 Answers

5 votes

Answer:

I think it is:

(B. The len ( ) function will run with each iteration, printing the element number each time.)

Step-by-step explanation:

User Hexalys
by
3.6k points
2 votes

Answer:

Option C

Step-by-step explanation:

Complete question

Why is the len ( ) function useful when using a loop to iterate through a stack?

The len ( ) function will print the elements of the stack.

The len ( ) function will run with each iteration, printing the element number each time.

The len ( ) function will tell the program the number of elements in the stack.

The len ( ) function will remove the duplicate elements in the stack.

Solution

A len()function in stack is used to extract the length of the given string, array, list, tuple etc. This function helps in optimizing the performance of the program by not calculating the objects contained in it but by providing the number of elements.

hence, option C is correct

User Tastybrownies
by
3.5k points