Recently in Python I have encountered this statement:
board.append([' '] * 8)
I have tried to search the Internet with Google to find some more information about this type of statement, but I can’t.
I know what the statement does, but I do not understand how, in what manner is doing, that.
This is the first time I have seen the * operator used on a list. Can you please refer me to a place where I can find some more information about this type of statements?
Most of the relevant operators and methods are defined here: Sequence Types.
Specifically
s * nis defined asHere,
sis a sequence andnis a number.Thus,
[' '] * 8returns a list consisting of eight' '.board.append()appends the result toboard, which presumably is a list (of lists).