+ 1

Idon't no why we use for rather than while could y please help me?!

6th Aug 2017, 8:24 PM
Mj.shabani
Mj.shabani - avatar
2 Respostas
+ 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.
6th Aug 2017, 8:49 PM
LynTon
LynTon - avatar
+ 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.
6th Aug 2017, 10:47 PM
Myke Albuquerque Pinto de Oliveira
Myke Albuquerque Pinto de Oliveira - avatar