0

Why the output is like this??

In the following code the last element is printed twice. Why?? https://code.sololearn.com/cfsCdFKRxcLB/?ref=app

7/19/2019 5:58:30 PM

Akash Sil

3 Answers

New Answer

+4

According to me In list elements↓ A total 6 B total 5 See you for loop will only repeat the condition till it takes so it is going to repeat the process When you print because of -1 condition it take the second number as repetition because for loop has to complete the number of round it has been said

+3

if you run this, you will see what is going on: a = [0, 1, 2, 3, 4, 5] for a[-1] in a: print(a[-1]) print(a) I read these: https://stackoverflow.com/questions/34706506/difference-between-for-a-1-in-a-and-for-a-in-a-in-python https://stackoverflow.com/questions/34695538/for-loops-and-iterating-through-lists but I'm still trying to get my head around the answers.... ;/

0

David Ashton Me too