I am new to Python and want convert this small JavaScript code to Python. How can I do that?
for (var y = 0; y < 128; y += 1024) {
for (var x = 0; x < 64; x += 1024) {
// skipped
}
}
I searched a lot in Google, but found nothing.
for
loops in PythonIt can be easily converted using range()
or xrange()
function. The xrange()
is an iterator version, which means it is more efficient (range()
would first create a list you would be iterating through). Its syntax is the following: xrange([start], stop[, step])
. See the following:
for y in xrange(0, 128, 1024):
for x in xrange(0, 64, 1024):
# here you have x and y
But I hope you have noticed, that due to the fact, that you are incrementing y
and x
with each respective loop by 1024, you will actually receive something similar to this:
var y = 0;
var x = 0;
or, in Python:
x = 0
y = 0
Anyway, it is just additional note about the code you have given as example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With