# 如何编辑类的实例？

##### 问题描述投票：0回答：1

``````1 2 3
4 5 6
7 8 *
``````

``````class symbol:

def __init__(self, x, y, val):
self.x = x
self.y = y
self.val = val

s1 = symbol(1, 1, "1")
s2 = symbol(2, 1, "2")
s3 = symbol(3, 1, "3")

s4 = symbol(1, 2, "4")
s5 = symbol(2, 2, "5")
s6 = symbol(3, 2, "6")

s7 = symbol(1, 3, "7")
s8 = symbol(2, 3, "8")
s9 = symbol(3, 3, "*")

def getPos():
xPos = 0
yPos = 0
for element in symbols:
if element.val == "*":
xPos = element.x
yPos = element.y
else:
pass

return xPos, yPos

def find(x, y):
xPos = 0
yPos = 0
found = symbol(100, 100, "FIND")

for element in symbols:
if element.x == x and element.y == y:
found.x = x
found.y = y
found.val = element.val
else:
pass
return found

def up():
x, y = getPos()

if y > 1:
newBlock = find(x, y-1)
myBlock = find(x, y)

myBlock.val = newBlock.val
newBlock.val = "*"
clear()
draw()
print(f"myBlock: {myBlock.val} ({myBlock.x}, {myBlock.y}), newBlock: {newBlock.val} ({newBlock.x}, {newBlock.y})")
else:
pass
#cannot go higher
``````
python class
##### 1个回答
0

``````for element in symbols:
if element.x == x and element.y == y:
return element
return None
``````