Added info that For loop is faster than while loop. (#25416)

pull/25637/head
Mukesh Jha 2018-12-20 07:16:28 +05:30 committed by Randell Dawson
parent 836897aea8
commit 663b293904
1 changed files with 3 additions and 0 deletions

View File

@ -228,6 +228,9 @@ Output:
['THIS', 'IS', 'AWESOME', 'SHINNING', 'STAR']
>
```
A interesting fact is that for loop is a bit faster compared to while loop in python. Because in for loop range/xrange is used which is implemented in C(in python's library) whereas in while loop we make use of some incremental statement specifically at the end of sentence like (i+=1) which is interpreted. Thus for loop is faster than while loop. Reference:
https://stackoverflow.com/questions/869229/why-is-looping-over-range-in-python-faster-than-using-a-while-loop
#### More Information: