python创建固定长度的空列表

python创建固定长度的空列表的两种方法

方法一

a = 10
x = [’’ for i in range(a)]
print(x)
#[’’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’]

方法二

a = 10
x = [None]*a
print(x)
#[None, None, None, None, None, None, None, None, None, None]

注意两种方法区别,一个是空字符,一个是None

你可能感兴趣的:(Python,python,列表)