0
what is the different between ?
list =[101,23,403,54,45]; list.sort(); print(list); and list =[101,23,403,54,45]; list=list.sort(); print(list);
7 Answers
+ 1
in python you can do list sorting by two ways:
sorted(my_list)
return a sorted copy of my_list (my_list is kept unchanged)
my_list.sort()
sort in-place (my_list is updated to be sorted, no return value -- ie: None is returned)
+ 5
Pawan Kumar
In second case actually you are printing list.sort() not list so list.sort() will print None.
+ 1
Hmm I understand
0
But in case 5 print
0
name="pawan";
get=len(name);
print(get);
0
Pawan Kumar
Here you are getting length of string which returns integer.
In above case you are printing sort() function which print None because function sort() doesn't return anything so if you print that function then None will be display.
0
Pawan Kumar
len () function returns integer value but sort() doesn't returns anything so it will display None.