+ 1

Why the 2nd output is this?? (Python )

L1=[1,3,5,7,9] print (L1==L1.reverse ()) print (L1) 1st Output:False 2nd Output:[9,7,5,3,1] The 2nd expression is comparing the lists then why the list is changed.

1st Oct 2020, 3:03 PM
Dark Killer
Dark Killer - avatar
3 ответов
+ 4
L1.reverse() reverses the list "in place". This means that the actual list is changed (reversed) whenever you call this method. If you want a method that returns the reverse of L1, you can use reversed(L1).
1st Oct 2020, 4:56 PM
Russ
Russ - avatar
+ 5
L1.reverse() doesn't returns new list ,rather it reverses the elements of the original list try printing L1.reverse()
1st Oct 2020, 3:08 PM
Abhay
Abhay - avatar
+ 3
#try in python write this: help(list.reverse)
1st Oct 2020, 4:08 PM
Sousou
Sousou - avatar