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);

31st May 2021, 9:19 AM
๐—ฃ๐—ฎ๐˜„๐—ฎ๐—ป ๐—ž๐˜‚๐—บ๐—ฎ๐—ฟ ๐Ÿ…Ÿ๏ธŽ๐Ÿ…š๏ธŽ
๐—ฃ๐—ฎ๐˜„๐—ฎ๐—ป ๐—ž๐˜‚๐—บ๐—ฎ๐—ฟ ๐Ÿ…Ÿ๏ธŽ๐Ÿ…š๏ธŽ - avatar
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)
31st May 2021, 5:47 PM
visph
visph - avatar
+ 5
Pawan Kumar In second case actually you are printing list.sort() not list so list.sort() will print None.
31st May 2021, 9:25 AM
AอขJ
AอขJ - avatar
+ 1
Hmm I understand
31st May 2021, 1:40 PM
๐—ฃ๐—ฎ๐˜„๐—ฎ๐—ป ๐—ž๐˜‚๐—บ๐—ฎ๐—ฟ ๐Ÿ…Ÿ๏ธŽ๐Ÿ…š๏ธŽ
๐—ฃ๐—ฎ๐˜„๐—ฎ๐—ป ๐—ž๐˜‚๐—บ๐—ฎ๐—ฟ ๐Ÿ…Ÿ๏ธŽ๐Ÿ…š๏ธŽ - avatar
0
But in case 5 print
31st May 2021, 1:09 PM
๐—ฃ๐—ฎ๐˜„๐—ฎ๐—ป ๐—ž๐˜‚๐—บ๐—ฎ๐—ฟ ๐Ÿ…Ÿ๏ธŽ๐Ÿ…š๏ธŽ
๐—ฃ๐—ฎ๐˜„๐—ฎ๐—ป ๐—ž๐˜‚๐—บ๐—ฎ๐—ฟ ๐Ÿ…Ÿ๏ธŽ๐Ÿ…š๏ธŽ - avatar
0
name="pawan"; get=len(name); print(get);
31st May 2021, 1:10 PM
๐—ฃ๐—ฎ๐˜„๐—ฎ๐—ป ๐—ž๐˜‚๐—บ๐—ฎ๐—ฟ ๐Ÿ…Ÿ๏ธŽ๐Ÿ…š๏ธŽ
๐—ฃ๐—ฎ๐˜„๐—ฎ๐—ป ๐—ž๐˜‚๐—บ๐—ฎ๐—ฟ ๐Ÿ…Ÿ๏ธŽ๐Ÿ…š๏ธŽ - avatar
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.
31st May 2021, 1:23 PM
AอขJ
AอขJ - avatar
0
Pawan Kumar len () function returns integer value but sort() doesn't returns anything so it will display None.
31st May 2021, 1:24 PM
AอขJ
AอขJ - avatar