Home>
I want to know

In Java

for (int a = 0;a<10;a ++) {}


When writing in Python

a = 0
while a<10:
    a = a + 1


Is this way of writing common?
I do not know if the Python for statement can do the same thing as the Java for statement, so it is written like this.

  • Answer # 1

    If you just repeat 10 times, it would be common to write:

    for a in range (10):
        ...

    The Python for statement is equivalent to the extended for statement in Java.
    There is no conventional C-style for statement with an initialization part, a condition part, and an update part.

  • Answer # 2

    for a in range (0, 10):
    Then a changes to 0, 1, ,,, 9.

    range (9, 10, 2) and see what happens.