+ 1
Idon't no why we use for rather than while could y please help me?!
2 Respuestas
+ 6
A basic example:
https://code.sololearn.com/cBN3sCawrFVQ/?ref=app
The for loop is also able to work through strings (also lists, dictionaries etc.) and check through every character in it (including spaces if required) rather than the while loop which is used to do something while an expression is true.
+ 2
While loop is the most flexible and for loop is used to iterate lists, tuples and dictionaries as well as when you already know how many times you want Python repeat the code using range object.