From the course: Python Theory for Network Engineers
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Conditional logic: For and while loops - Python Tutorial
From the course: Python Theory for Network Engineers
Conditional logic: For and while loops
- Let's talk about another powerful tool in Python, which is Loops. What is a Loop? A Loop is a block of code that executes many times. And typically we want to specify a certain condition for the block of code to run. And that condition could be a For Loop. A For Loop runs as many times as you specify or it could be repeated once for each of the item in a collection. This is typically used to iterate over the elements of a sequence, such as in a list or a tuple. The letter "I" in this example that we saw is just a place holder. That could be anything. In most cases, we want to make it explicit and match it to what we have. So, in the two For Loops that we saw, the "for I in range(10)" it basically repeats for all the numbers from zero to nine and "I" would just be a placeholder. So, the first time we run would be zero, and then one, and two, and three and four and so on, so forth. Or it could be repeated…
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
-
-
-
-
-
Conditional logic: If/then and compare values2m 49s
-
(Locked)
Lab: Demonstrating if/then and value comparison3m 4s
-
(Locked)
Conditional logic: For and while loops2m 47s
-
(Locked)
Lab: Demonstrate for and while loops5m 4s
-
(Locked)
Challenge: Making your script do repeatable tasks1m 4s
-
(Locked)
Solution: Making your script do repeatable tasks2m 19s
-
-
-
-