+ 2

Why should we use for each loop in python

22nd Jul 2019, 6:03 AM
SUNDARAMAN IYER
SUNDARAMAN IYER - avatar
2 Answers
+ 3
It is termed as for loop in python, not for each loop. But it is similar to for loop in other languages. According to it's syntax it sounds more meaningful when called for each. Example:- for i in func() : This sounds more meaningful as for each i in func().
23rd Jul 2019, 3:14 PM
Manoj
Manoj - avatar
+ 6
There is no foreach loop in Python. By default the for loop behaves likes a foreach loop. It is just that Python also created a handy range() object that lets you sequentially generate numbers in a linear increment.
22nd Jul 2019, 6:13 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar