list.sort() 返回 Nome,因此变量 a 正在接收我这样固定的无值:
list = input("Enter the elements of the list, comma separate : ").split(',')
list.sort()
a = list
print("Sorted in ascending order: ", a)
list.sort(reverse = True)
b = list
print("Sorted in descending order: ", b)
这是 int 的结果
Enter the elements of the list, comma separate : 1,7,8,9,7,5,4,6
Sorted in ascending order: ['1', '4', '5', '6', '7', '7', '8', '9']
Sorted in descending order: ['9', '8', '7', '7', '6', '5', '4', '1']
和字符串
Enter the elements of the list, comma separate : a,b,r,e,ra
Sorted in ascending order: ['a', 'b', 'e', 'r', 'ra']
Sorted in descending order: ['ra', 'r', 'e', 'b', 'a']