This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author varada86
Recipients paul.moore, steve.dower, tim.golden, varada86, zach.ware
Date 2018-06-09.17:44:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1528566250.8.0.592728768989.issue33815@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,
As per my understanding, 
a = [0]*19 -> creates a list of length 19 with all zeros,

>>> a = [0]*19
>>> print (len(a))
19
>>> a [18] = 2
>>> print (a)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2]
>>>

In the similar way, 
>>> a = []*19 --> Must create a blank list with length 19. 
That is eventhough the contents of the list would be blank or null, I would at least expect the length of the list must 19 and the index must have got memory allocated so I can access it later ?

Otherwise, if a = []*19 is going to return length as 0, and it's index cannot be accessed then what difference does it have with a = []. Aren't they the same ? There should be some significance of using a = []*19 compared to a = []. They cant the the same, can they ?

>>> a = []*19
>>> a [18] = 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list assignment index out of range
>>> print (len(a))
0
>>>
>>> b = []
>>> print (len(b))
0
>>> b [18] = 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list assignment index out of range
>>>

-----
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
History
Date User Action Args
2018-06-09 17:44:10varada86setrecipients: + varada86, paul.moore, tim.golden, zach.ware, steve.dower
2018-06-09 17:44:10varada86setmessageid: <1528566250.8.0.592728768989.issue33815@psf.upfronthosting.co.za>
2018-06-09 17:44:10varada86linkissue33815 messages
2018-06-09 17:44:10varada86create