I'm just curious about the following code fragment not working, which should initialize an empty list and on-the-fly append an initial value. The second fragment is working. What's wrong with it? Is there a best practice for such initializing?
>>> foo = [].append(2)
>>> print foo
None
>>> foo = []
>>> foo.append(2)
>>> print foo
[2]
EDIT: Seems I had a misunderstanding in the syntax. As already pointed out below, append always returns None as a result value. What I first thought was that [] would return an empty list object where the append should put a first element in it and in turn assigns the list to foo. That was wrong.