From the course: Python: Programming Efficiently

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Design efficient loops

Design efficient loops - Python Tutorial

From the course: Python: Programming Efficiently

Start my 1-month free trial

Design efficient loops

- [Instructor] Looping constructs and the idea of iterating through data are so common and important in everyday programming that is worth taking the time to understand in depth how they work in Python. We begin by importing a number of Python modules that will come useful. Python loops are much simpler than in C. It's not just the syntax. As we saw, we don't have to take care of initializing a counter, updating it and checking its value to see if we need to drop out of the loop. This is because Python loops express a more general and simpler concept. We operate individually on the elements of a sequence. Let's take as an example the Fibonacci numbers. A sequence where each number is the sum of the two preceding ones. So it goes one, one, two, three, five, eight, 13, 21. Here it is as a Python list. Fibonacci numbers appear in many situations in nature, such as the branching of trees, the arrangement of leaves on a…

Contents