Learning Python: Weird things about list

y = []  # declaring a constructor. This is equivalent to y = list()
y.append('book') #append book into the list
print y
y.append('pen')  #append pen into the list
y.append('pencil') #append pencil into the list
print y
print y.sort()  #I thought this would print the list but nope. It prints None
print y
t = y.sort() # doesn'tsort on the fly, it read the y = []
print t
y.sort()
print y



f = [1,2,'a','b']
f.sort()
print f

['book']
['book', 'pen', 'pencil']
None
['book', 'pen', 'pencil']
None
['book', 'pen', 'pencil']
[1, 2, 'a', 'b']


Just to look at things line by line


>>> y.append('book') #append book into the list
>>> print y
['book']
>>> y.append('pen')  #append pen into the list
>>> y.append('pencil') #append pencil into the list
>>> print y
['book', 'pen', 'pencil']
>>> print y.sort()  #I thought this would print the list but nope. It prints None
None
>>> print y
['book', 'pen', 'pencil']
>>> t = y.sort() # doesn'tsort on the fly, it read the y = []
>>> print t
None
>>> y.sort()
>>> print y
['book', 'pen', 'pencil']
>>> f = [1,2,'a','b']
>>> f.sort()
>>> print f
[1, 2, 'a', 'b']