Skip to main content

8.3) None Type (cont'd)


None is also useful for initialising lists. You can’t access elements of a list that haven’t been assigned a value. If you want to increate the size of a list, you have to expand it with the method append(). An alternative is to create a list of None values with a specific length and then assign values to the elements of a list with the indexing method.

>>> L=[None]*5     # this is handy to initialise a list
>>> L[2]=10.0      # and then populate it
>>> print L
[None, None, 10.0, None, None]