From the course: Python Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Control flow

Control flow

- [Instructor] This is where programming really starts to get powerful. There are three main types of control flow that we're going to cover and the first of these is the if statement. So this is pretty straightforward, a equals true, if a: print It is true. And if I change a to false, nothing prints out. So notice that I've indented in the line after my if statement here. So this colon followed by an indent means that everything indented under this line belongs under the if statement. It sort of belongs to the if statement. So any indented code is executed only if a is true. I could add another indented print line, Also print this, and now both of these lines belong under the if statement. We say we're in the if block, a block of code as these indented lines under here. Now, I could also outdent and add another line, Always print this. We see that even if a is false, this gets printed out because it doesn't belong to…

Contents