Перейти к содержимому

Python Control Flow I: If, Else, Elif, For and While Loops

Xavier Chee

0:00 / 0:00

Python Control Flow I: If, Else, Elif, For and While Loops

3 просмотра · 3 дн. назад
Xavier Chee
11 подписчиков
3 просмотра · 3 дн. назад
WHAT THIS COVERS (a) Control flow: what it is, and how it changes the rule that every line runs once, from top to bottom. (b) The if statement: the condition and the colon, how Python knows which lines belong to an if, and the difference between = and == in a condition, with the error Python gives when they are mixed up. if and else: one block for true and one for false. elif: more than two outcomes, which block runs when more than one condition is true, and why the order of the checks matters. Combining conditions with and and or, and using or to shorten a chain of elif statements. (c) An if inside a for loop: counting the items that pass a test with a counter, what the counter line means, where the print line goes, and adding values up to find a mean. The range() function with one, two or three numbers, and the underscore as a loop name when the number is not used. Looping over the items of a list rather than their positions with range(len()). (d) The while loop: when to choose it over a for loop, how it checks its condition again after every pass, and tracing one pass by pass. The infinite loop: what causes one, how to check a while loop before you run it, and how to stop one in the scratchpad or a terminal. CHAPTERS 0:00 What you will be able to do 0:32 What control flow is 0:47 The Python if statement 1:52 if and else 2:18 elif: more than two outcomes 3:15 Combining conditions with and / or 4:08 Counting with an if inside a for loop 5:31 The range() function 6:39 Looping over items, not positions 6:55 The Python while loop 7:56 Infinite loops and how to stop them 8:46 Summary THE COURSE Every snippet here can be run in the scratchpad beside the lesson, in your browser, with nothing to install: https://mscphm.github.io/bridging-cou... Previous lesson: Python List, Dictionary and Set Methods Link:    • Python Data Structure II: Python List, Dic...   Next lesson: leaving a loop early, skipping items, and keeping track of each item's position.