python - Python更改字段的第一个值
问题描述
我尝试将python中字段的第一个值更改为true。我究竟做错了什么?整个专栏都发生了变化,我不明白为什么。
我的代码:
def selectElement(self, col, row):
print(col, row)
print(self)
self.field[col][row] = True
print(self)
def __str__(self):
out = '\n'
for col in self.field:
for value in col:
out += str(value) + ' '
out += '\n'
return out
输出:
0 0
False False False
False False False
False False False
True False False
True False False
True False False
列表初始化为:
self.list = [[False] * size] * size
解决方案
我修复了它:
self.field = [[False] * size for n in range(size)]
推荐阅读
- c# - 从 C# 创建 dbf 表 - DateTime 字段的问题
- reactjs - 如何在反应中打印文本输出
- amazon-quicksight - QuickSight:使用减号运算符时计算字段的问题
- c - Pointer to pointer in c,
- php - 将 php 与 postgresql 链接
- c# - C# execute, wait, read command's output
- command-line - Resize image and create 3x3 tiles with ImageMagick
- python - Google.api_core.exceptions.BadRequest: 400 Invalid credential
- reactjs - 无法将状态中的数据渲染到 React 组件中
- lua - 无法更改为之前的 io 输入