Is there a better way to create a list of None objects?

Dennis Lee Bieber wlfraed at ix.netcom.com
Thu Aug 12 11:43:51 EDT 2021


On Thu, 12 Aug 2021 09:57:33 +0100, Stephen Tucker <stephen_tucker at sil.org>
declaimed the following:


>
># Logic             Effect
>
>#
>
># [None * 8]        TypeError: unsupported operand type(s) for *: ...
>
># [(None) * 8]      TypeError: unsupported operand type(s) for *: ...
>
># [((None)) * 8]    TypeError: unsupported operand type(s) for *: ...
>
># [(None,) * 8]     [(None, None, None, None, None, None, None, None)]
>
># list ((None) * 8) TypeError: unsupported operand type(s) for *: ...
>

	In all the above, you've put the *8 INSIDE the list structure. You
"working" example is actually creating a TUPLE stored (as the only element)
inside a LIST.

>>> [None] * 8
[None, None, None, None, None, None, None, None]
>>> 

	Creates a LIST of 8 elements, each being None.


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Python-list mailing list