我需要一些帮助来理解以下代码:
nextState = ((nextx, nexty), self.corners) if self.currentPosition not in self.corners else ((nextx, nexty), tuple([i for i in self.corners if i != self.currentPosition]))
successors.append((nextState, action, 1))
有人能告诉我这条条件语句在多行中的含义,而不仅仅是一行if语句吗?
答案 0 :(得分:0)
作为if
语句,这将是:
if self.currentPosition not in self.corners:
nextState = ((nextx, nexty), self.corners)
else:
nextState = ((nextx, nexty), tuple([i for i in self.corners if i != self.currentPosition]))
successors.append((nextState, action, 1))
这实际上是Python的ternary operator形式。