You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
696 B

4 months ago
class Array2D:
"""
说明
1.构造方法需要两个参数即二维数组的宽和高
2.成员变量w和h是二维数组的宽和高
3.使用对象[x][y]可以直接取到相应的值
4.数组的默认值都是0
"""
def __init__(self, w, h, default=0):
self.w = w
self.h = h
self.data = []
self.data = [[default for y in range(h)] for x in range(w)]
def debug_show(self):
for y in range(self.h):
for x in range(self.w):
print(self.data[x][y], end=' ')
print("")
def __getitem__(self, item):
return self.data[item]