2.1 - Control Flow

Ha Khanh Nguyen (hknguyen)

1. if, elif, and else Statements

1.1 Standard statements

Exercise 1: We are given 2 numbers stored in variables a and b. Write a program to print the number with the larger value.

Exercise 2: We are given 2 strings s1 and s2. If one is contained in the other, print "One is a substring of the other!". Otherwise, print "They are distinct strings!"

1.2 Ternary expressions

2. Loops

2.1 for loops

2.2 range() function

2.3 continue keyword

2.4 break keyword

2.5 while loops

This lecture note is modified from Chapter 2 of Wes McKinney's Python for Data Analysis 2nd Ed.