Control Flow in Python - If Elif Else Statements

未能成功加载,请稍后再试
0/0

In almost every program there are times you need to make decisions and that's when you use.

And if statement, Here is an example, Let's say we have a variable called temperature, we set it to 35. Now, if temperature is greater than 30, perhaps we want to display a message to the user.

So we use an if statement if after if we add a condition which is basically a boolean expression, an expression that produces a boolean value.

So if temperature is greater than 30 here, we have a boolean expression.

If this expression evaluates to true, the following statements will be executed.

Let me show you.

Now, here's the important part that a lot of beginners miss, when you use, an if statement.

You should always terminate your statement with a colon Now.

Let's see what happens when I press.

Enter our cursor is indented.

下载全新《每日英语听力》客户端,查看完整内容