Update Translation for Chinese (#21672)

Update translation for Chinese and fix indentation for code block.
This commit is contained in:
Lam Chi Tak
2018-12-28 01:43:01 +08:00
committed by Jingyi Ding
parent df11c40023
commit 930e1fefb3

View File

@ -1,10 +1,10 @@
--- ---
title: If Elif Else Statements title: If Elif Else Statements
localeTitle: 如果Elif Else声明 localeTitle: If / Elif / Else语句
--- ---
## 如果Elif Else声明 ## If / Elif / Else语句
`if` / `elif` / `else`结构是控制程序流的常用方法,允许您根据某些数据的值执行特定的代码块。如果关键字`if`后面的条件计算`true` ,则代码块将执行: 请注意,在条件检查之前和之后不使用括号,如同其他语言一样。 `if` / `elif` / `else`结构是控制程序流的常用方法,允许您根据某些数据的值执行特定的代码块。如果关键字`if`后面的条件表达式返回`True` ,则代码块将执行: 请注意,在条件检查之前和之后不使用括号,如同其他语言一样。
```python ```python
if True: if True:
@ -18,7 +18,7 @@ x = 5
print("The condition was true!") #this statement executes print("The condition was true!") #this statement executes
``` ```
如果条件为`false` ,您可以选择添加将执行的`else`响应 您可以选择添加`else`执行条件为`False`的代码块
```python ```python
if not True: if not True:
@ -27,7 +27,7 @@ if not True:
print('Else statement will execute!') print('Else statement will execute!')
``` ```
或者你也可以看这个例子 或者你也可以看这个例子
```python ```python
y = 3 y = 3
@ -38,9 +38,9 @@ y = 3
print("The condition wasn't true!") #this statement executes print("The condition wasn't true!") #this statement executes
``` ```
_请注意 `else`关键字后面没有条件 - 它捕获条件为`false`所有情况_ _请注意 `else`关键字后面没有条件 - 它捕获条件为`False`所有情况_
可以通过在初始`if`语句之后包含一个或多个`elif`检查来检查多个条件,但只执行一个条件: 可以通过在初始`if`语句之后包含一个或多个`elif`来检查多个条件,但只执行一个条件:
```python ```python
z = 7 z = 7
@ -55,11 +55,11 @@ z = 7
print("Neither will I!") #this statement does not execute print("Neither will I!") #this statement does not execute
``` ```
_请注意只有第一个计算为`true`条件才会执行。即使`z > 6`为`true` `if/elif/else`块`if/elif/else`在第一个真实条件之后终止。这意味着只有在没有条件`true`的情况下才会执行`else` 。_ _请注意只有第一个计算为`True`条件才会执行。即使`z > 6`为`True` `if/elif/else`块在第一个真实条件之后终止。这意味着只有在没有条件为`True`的情况下才会执行`else` 。_
我们还可以创建嵌套if用于决策。在此之前请参阅前面的href ='https//guide.freecodecamp.org/python/code-blocks-and-indentation'target ='\_ blank'rel ='nofollow'>缩进指南。 我们还可以创建嵌套if用于决策。在此之前请参阅前面的href ='https//guide.freecodecamp.org/python/code-blocks-and-indentation'target ='\_ blank'rel ='nofollow'>缩进指南。
让我们举个例子来找一个偶数大于'10'的数字 让我们举个例子来找一个偶数大于'10'的数字
``` ```
python python
x = 34 x = 34
@ -78,7 +78,7 @@ python
**_内联python if-else语句_** **_内联python if-else语句_**
我们也可以使用if-else语句内联python函数 以下示例应检查数字是否大于或等于50如果是则返回True 我们也可以使用if-else语句内联python函数以下示例应检查数字是否大于或等于50如果是则返回`True`
``` ```
python python
x = 89 x = 89
@ -87,7 +87,7 @@ python
print(is_greater) print(is_greater)
``` ```
产量 输出
``` ```
> >
True True