From the course: Python for JavaScript Developers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Iterating in Python - Python Tutorial
From the course: Python for JavaScript Developers
Iterating in Python
- [Instructor] In Python, a deeper understanding of iterations may help you write code that is easier to reason about. As an added bonus, you may achieve significant performance improvements to your programs. So let's take a look at an example of this. Here, we iterate over a list that goes from 1 to 5, and for each number we print a string with the number in it and then we print the number + 1. So we can imagine these numbers on a conveyor belt, if you will, that drops these numbers into the code block where different things are done with the numbers. So looking at this example, do we need this list hard coded there in order to use this for-loop syntax? And the answer is no. We can use Python's built-in range, and a range from 1 to 6 will yield similar results. And there's a reason I say similar. We can think of this as having the same outcome, but there's an added bonus that comes with it, and let me show you what I…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Iterating in Python3m 46s
-
(Locked)
Writing concise code with zip and enumerate3m 39s
-
(Locked)
From JavaScript map and filter to an elegant Python comprehensions6m 2s
-
(Locked)
Decorators are essential3m 35s
-
(Locked)
Challenge: Map to comprehension5m 19s
-
(Locked)
Solution: Map to comprehension2m 32s
-
(Locked)
-