# -*- coding: utf-8 -*-
"""
Created on Thu Nov 8 09:55:02 2018
@author: BigFly
"""
num_list=[1000]*10
list_list =[[]]*10
set_list =[set()]*10
print(num_list)
print(list_list )
print(set_list )
print("对 0 号元素操作")
num_list[0]+=6
print(num_list)
list_list[0].append(6)
print(list_list )
set_list[0].add(6)
print(set_list )
print("正确写法")
list_list =[[] for i in range(10)]
list_list[0].append(6)
print(list_list )
运行结果:
[1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]
[[], [], [], [], [], [], [], [], [], []]
[set(), set(), set(), set(), set(), set(), set(), set(), set(), set()]
对 0 号元素操作
[1006, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]
[[6], [6], [6], [6], [6], [6], [6], [6], [6], [6]]
[{6}, {6}, {6}, {6}, {6}, {6}, {6}, {6}, {6}, {6}]
正确写法
[[6], [], [], [], [], [], [], [], [], []]
网友评论