Make A List


#1



Why is it that this...

board = []

for x in range(5):
    board.append("O" * 5)

print board

... does not work, but this...

board = []

for x in range(5):
    board.append(["O"] * 5)

print board

...does? What distinction does the square brackets around the "O" make to the code?


#2

Hi, @jwok90 ,

Check it out with two print statements to see the difference ...

print "O" * 5
print ["O"] * 5

Multiplying a str by an int gives us a str with the original characters repeated the specified number of times.

Multiplying a list by an int gives us a list with the items in the original list repeated the specified number of times.


#3

Got it - thanks @appylpye!


#4