我正在使用processing.py
我正在关注这个(Java)
https://www.youtube.com/watch?v=H7frvcAHXps
我想知道我是否可以在python中使用相同类型的for循环
for(int y = 0; y < height; y = y + cellSize):
for(int x = 0; x < width; x = x + cellSize):
rect(x, 0, cellSize, cellSize)
我尝试运行代码时收到错误:
processing.app.SketchException: Maybe there's an unclosed paren or quote mark somewhere before this line?
我想在python中使用相同类型的嵌套for循环(在单行上)可能有一种简单但略有不同的方式
答案 0 :(得分:2)
这在python中是等价的。在range(0, height, cellSize)
中,0
和height
是范围的范围,cellSize
是计数器增量的数量。
for y in range(0, height, cellSize):
for x in range(0, width, cellSize):
rect(x, 0, cellSize, cellSize)