What is the difference between for i in range(l) and for i in l?why we use in with for loop?Can anyone give me a explanation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between for i in range(l) and for i in l?why we use in with for loop?Can anyone give me a explanation

17th Apr 2020, 4:37 PM
Benson Thomas
3 Answers
0
It is easiest way to excute loop. It is very less syntax. https://code.sololearn.com/cGpJghPeFyC5/?ref=app
17th Apr 2020, 4:49 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
0
No difference.. You'll get an idea, when you use them with lists or strings..
17th Apr 2020, 4:57 PM
sarada lakshmi
sarada lakshmi - avatar
0
It depends on what the variable 'l' is. if l is a string, list, tuple or a dictionary, you can use for i in l. But assuming you want to maybe countdown to zero or up from 0, range is useful. Eg. For i in range(5): print i. You will get 01234. You should get acquainted with them. You'd understand more as you use them.
17th Apr 2020, 5:28 PM
Tomiwa Joseph
Tomiwa Joseph - avatar