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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
forloops in PythonIt can be easily converted using
range()orxrange()function. Thexrange()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:Note
But I hope you have noticed, that due to the fact, that you are incrementing
yandxwith each respective loop by 1024, you will actually receive something similar to this:or, in Python:
Anyway, it is just additional note about the code you have given as example.