num_list = [34, 54, 78, 23, 54, 65, 67, 23, 56, 67, 23]
Type your code below
print(num_list.sort(reverse=True))
Q. Why does this gives "None" as output?
num_list = [34, 54, 78, 23, 54, 65, 67, 23, 56, 67, 23]
print(num_list.sort(reverse=True))
Q. Why does this gives "None" as output?
Please try this …
num_list = [34, 54, 78, 23, 54, 65, 67, 23, 56, 67, 23]
num_list.sort(reverse=True)
print(num_list)
Hey Shirish,
Thanks a lot for replying.
My doubt is why does "print(num_list.sort(reverse=True))" gives None as output?
Hi Mridul,
The return type of list.sort() is None. This is because the list is sorted in-place. What you want is sorted(list) or print the sorted list separately which returns the new sorted list.
As mentioned by Shirish, you can use the following code:
num_list = [34, 54, 78, 23, 54, 65, 67, 23, 56, 67, 23]
num_list.sort(reverse=True)
print(num_list)
You can also refer to this doc.
Thanks,
Bhavika