Python - printing sorted lists | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python - printing sorted lists

Hi, Why does the first printing not output a sorted list, but a None instead? The second printing works. a = [4,2,3,1] print (a.sort()) a.sort() print (a) Output: None [1,2,3,4] Please help.

19th Jun 2019, 9:22 AM
Marek Kluczewski
Marek Kluczewski - avatar
2 Answers
+ 1
Ok, why print(a.sort()) is implicit and print(sorted(a)) is explicit?
19th Jun 2019, 9:52 AM
Marek Kluczewski
Marek Kluczewski - avatar
0
If I understand it correctly, Print + method -> None Print + function -> value, iterator etc.
19th Jun 2019, 10:07 AM
Marek Kluczewski
Marek Kluczewski - avatar