From 663b29390497ad52fbae07d8445ac06d207d6470 Mon Sep 17 00:00:00 2001 From: Mukesh Jha Date: Thu, 20 Dec 2018 07:16:28 +0530 Subject: [PATCH] Added info that For loop is faster than while loop. (#25416) --- guide/english/python/for-loop-statements/index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/guide/english/python/for-loop-statements/index.md b/guide/english/python/for-loop-statements/index.md index 94b1309af4..c5f2e66315 100644 --- a/guide/english/python/for-loop-statements/index.md +++ b/guide/english/python/for-loop-statements/index.md @@ -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: