Defining a list in Python using the multiply operator

前端 未结 2 1776
迷失自我
迷失自我 2021-01-19 06:31

Recently in Python I have encountered this statement:

board.append([\' \'] * 8)

I have tried to search the Internet with Google to find som

2条回答
  •  误落风尘
    2021-01-19 06:55

    It works like this:

    >>> L = [0]*10
    >>> L
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    >>> 
    

    If you need to know how something works in Python, look it up in the Python documentation, or just experiment with it yourself.

提交回复
热议问题