What does 'does not return a value' mean?

Hi!
I am a bit confused,


Why does this show up as ‘None’ when I run it.
Surely if I have assigned the change to a variable, and then I print that variable it should come up.
The explanation is that " The .sort() method does not return any value and thus does not need to be assigned to a variable.", but not sure why it wouldn’t work if I happened to assign it to a variable.

I am sorry if the question doesn’t make a lot of sense, I’m a beginner and new to wording things. xd

Thank you all!

list.sort() is not assignable as anything other than None. It is an in-place operation so doesn’t need to be assigned. However, the original list is mutated in the process, of course.

Python has a function in the built-ins that will copy a list, then sort it, then assign it.

sorted_cities = sorted(cities)

See the differences? One of them is that the original list is not mutated.

Number two is that it is assignable. The iterable that we passed in to the function is cast to a list, sorted and returned as a list.

>>> a = 9,3,8,1,5,7,4,2,6
>>> (*sorted(a),)
(1, 2, 3, 4, 5, 6, 7, 8, 9)
>>> 

If it is iterable, it is sortable. Just takes some steps, is all.

>>> a = 'aquickbrownfoxjumpsoverthelazydog'
>>> (*sorted({*a}),)
('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z')
>>> 
>>> b = 'a a quick brown fox fox jumps over the the lazy dog'
>>> (*sorted({*b.split()}),)
('a', 'brown', 'dog', 'fox', 'jumps', 'lazy', 'over', 'quick', 'the')
>>> 
1 Like