Python Forum

Full Version: I don't understand this result
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
>>> f = [].extend(['spam', 32, 44])
>>> type(f)
         <class 'NoneType'>
>>> f = [].extend(['spam', 32, 44])
>>> f
>>> repr(f)
'None'
You need to define a list fist,then extend it.
>>> lst = []
>>> lst.extend(['spam', 32, 44])
>>> lst
['spam', 32, 44]
extend changes the list in place (and thus return None)

>>> f = [].extend(['spam', 32, 44])
>>> type(f)
<type 'NoneType'>
>>> f=[]
>>> f.extend(['spam', 32, 4])
>>> type(f)
<type 'list'>
>>> print f
['spam', 32, 4]
>>> f = [] + ['spam', 32, 44]
>>> type(f)