在while语句中分配变量



嗨,我正试图从matplotlib.pyplot.ginput获得一组点。我的想法是在列表中保存点,而actuaPoint!=lastPoint

是否可以这样做:

lastPoint = None
pointList = []
actualPoint = plt.ginput(1)
while (actualPoint=plt.input()) != lastPoint:
pointList.append(actualPoint)
lastPoint= actualPoint

?继续,我想知道是否有办法在while语句

中进行变量赋值

您需要使用赋值表达式,使用:=操作符。

point, = pointList = [plt.ginput(1)]
while (next_point := plt.input()) != point:
pointList.append(next_point)
point = next_point

最新更新