【发布时间】:2018-07-10 02:29:06
【问题描述】:
我正在尝试在 Python 中创建海龟列表。我可以通过以下方式手动实现:
import turtle
wn = turtle.Screen()
one = turtle.Turtle()
two = turtle.Turtle()
我希望使用以下 for 循环遍历海龟名称列表,但语法让我很困惑:
import turtle
wn = turtle.Screen()
for turtleName in ["one","two"]:
turtleName = turtle.Turtle()
one.left(60)
one.forward(160)
NameError: name 'one' is not defined
【问题讨论】:
-
不要这样做。使用
dict
标签: python list for-loop turtle-graphics