+ 2

Why can't I reverse lists

Whenever I use the list.reverse() method on a list, my programs displays none whenever I try to print the reverse Anyone know why and how to correct this?

6th May 2021, 4:35 PM
Iamebson
Iamebson - avatar
4 ответов
+ 5
List.reverse() won't display anything cause it updates the existing list. Try to print the list instead. letters = ['p', 'q', 'r', 's', 'p', 'u'] m=[1,2,3,4] print(letters.reverse(),m.reverse()) print(letters,m)
6th May 2021, 4:40 PM
Aditya
Aditya - avatar
+ 4
list.reverse() ,Reverses the elements of the list, in place. "in place" means the original list gets changed, rather than returning a new list, so the return you ask it to print is None.
6th May 2021, 4:41 PM
sarada lakshmi
sarada lakshmi - avatar
+ 3
sarada lakshmi your explanation taught me something I hadn't noticed since
6th May 2021, 4:52 PM
Iamebson
Iamebson - avatar