将 'BCH' 插入地图
Insert 'BCH' into map
我想在列表的特定位置插入 'BCH',但它给了我一条错误消息。
这是我的代码:
map = [[' ', ' ', ' ', ' '], \
[' ', ' ', ' ', ' '], \
[' ', ' ', ' ', ' '], \
[' ', ' ', ' ', ' ']
]
building = 'BCH'
map[0][1].append(building)
他们给出的错误信息是“AttributeError: 'str' object has no attribute 'append' “
字符串是不可变的,您不能在其上使用 .append()
。如果要连接到字符串,请使用赋值。
map[0][1] += building
我想在列表的特定位置插入 'BCH',但它给了我一条错误消息。 这是我的代码:
map = [[' ', ' ', ' ', ' '], \
[' ', ' ', ' ', ' '], \
[' ', ' ', ' ', ' '], \
[' ', ' ', ' ', ' ']
]
building = 'BCH'
map[0][1].append(building)
他们给出的错误信息是“AttributeError: 'str' object has no attribute 'append' “
字符串是不可变的,您不能在其上使用 .append()
。如果要连接到字符串,请使用赋值。
map[0][1] += building