0

why print(list.reverse()) does not work?

16th Mar 2017, 12:09 PM
suraj jadhav
suraj jadhav - avatar
7 Answers
+ 14
Try this. list1 = [1,2,3,4,5] print (list1) list1.reverse() print (list1)
16th Mar 2017, 12:17 PM
Hatsy Rei
Hatsy Rei - avatar
+ 14
I don't Python much, but deriving from programming logic: It's because list1.reverse() does not return a list to the print() function. What list1.reverse() does is to convert list1 to it's reversed counterpart. You need to manually print list1 after converting it.
16th Mar 2017, 12:21 PM
Hatsy Rei
Hatsy Rei - avatar
+ 13
Please post your entire code for inspection so members can help you tell which part is throwing an error.
16th Mar 2017, 12:11 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
it does not work because peint(list.reverse()) don't return a list, but convert just reverse list. you must explicitly affect answer with print function.
16th Mar 2017, 7:25 PM
Jessie
Jessie - avatar
0
list1 = [1,2,3,4,5] print (list1) print(list1.reverse()) Output: [1, 2, 3, 4, 5] None
16th Mar 2017, 12:13 PM
suraj jadhav
suraj jadhav - avatar
0
Your code worked but why my example gives 'none' as output
16th Mar 2017, 12:19 PM
suraj jadhav
suraj jadhav - avatar
0
okay, thanks
16th Mar 2017, 12:23 PM
suraj jadhav
suraj jadhav - avatar