+ 2

Python - Why is output None?

a=[24,13,32,18] print(a.sort())

12th Sep 2019, 5:27 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
3 Antworten
+ 11
sort() is an object method. It doesn't return value. It sort the value in place. sorted() also is a function which sorts items and returns as new values. i.e pop() method will return the popped item
15th Sep 2019, 11:37 PM
BlackRose Mike
BlackRose Mike - avatar
+ 2
.sort() is a function, so it needs to be called before printing you’d be better off doing a=[your numbers] a.sort() print(a)
12th Sep 2019, 5:34 PM
Glenn 🙏
Glenn 🙏 - avatar