python中sort()和sorted()之间的区别

时间:2018-07-17 08:05:04

标签: python python-3.x

我创建了一个程序来对列表进行排序,但是 sort()函数在Python中返回了 NONE 值,而 sorted() >给出排序后的数组。有什么区别?

提供正确的输出:

test_cases = int(input())
string1, string2 = map(str,input().split(' '))
for x in range (0,test_cases):
    list_s1 = list(string1)
    list_s2 = list(string2)
    new_list1 = sorted(list_s1)
    new_list2 = sorted(list_s2)
    print(new_list1,new_list2)

为什么在此没有输出?

test_cases = int(input())
string1, string2 = map(str,input().split(' '))
for x in range (0,test_cases):
    list_s1 = list(string1)
    list_s2 = list(string2)
    new_list1 =  list_s1.sort()
    new_list2 = list_s2.sort()
    print(new_list1,new_list2)

0 个答案:

没有答案