| **异步** | It is used to declare a function as a coroutine, much like what the `@asyncio.coroutine` decorator does.
`async`
它用来声明一个函数为协程,就像`@asyncio.coroutine`装饰器所做的一样。
```java
asyncdefping_server(ip):
```
|
| **等待** | It is used to call `async` coroutine.
`await`
它用于调用`async`协程。
```java
asyncdefping_local():
...
...
@@ -58,8 +70,10 @@ async def ping_server(ip):
```
|
| **类** | It is used to create a class.
`class`
它用于创建一个类。
```java
classUser:
...
...
@@ -68,8 +82,10 @@ async def ping_server(ip):
```
|
| **def** | It is used to create or define a function.
`def`
它用于创建或定义函数。
```java
defmy_function():
...
...
@@ -79,8 +95,10 @@ async def ping_server(ip):
```
|
| 的 | It is used to delete objects. In Python everything is an object, so the `del` keyword can also be used to delete variables, [lists](https://howtodoinjava.com/python/python-lists/), or parts of a list, etc.
| 如果为 | It is used to create conditional statements that allows us to execute a block of code only if a condition is `True`.
`if`
它用于创建条件语句,该条件语句仅在条件为`True`时才允许我们执行代码块。
```java
x=5
...
...
@@ -100,9 +120,10 @@ async def ping_server(ip):
```
|
| **elif** | It is used in conditional statements and is short for `else if`.
`elif`
它用于条件语句中,是`else if`的缩写。
```java
i=5
...
...
@@ -115,8 +136,10 @@ async def ping_server(ip):
```
|
| **其他** | It decides what to do if the condition is `False` in `if..else` statement.
`else`
它决定如果`if..else`语句中的条件为`False`时该怎么办。
```java
i=5
...
...
@@ -142,9 +165,15 @@ async def ping_server(ip):
```
|
| **试试** | 如果它包含任何错误,它将定义一个测试代码块。 |
| 除了 | It defines a block of code to run if the try block raises an error.
`try`
如果它包含任何错误,它将定义一个测试代码块。
`except`
如果`try`块引发错误,它将定义要运行的代码块。
```java
try:
...
...
@@ -154,8 +183,10 @@ async def ping_server(ip):
```
|
| **终于** | It defines a code block which will be executed no matter if the try block raises an error or not.
`finally`
它定义了一个代码块,无论`try`块是否引发错误,该代码块都将执行。
```java
try:
...
...
@@ -167,8 +198,10 @@ async def ping_server(ip):
```
|
| **加注** | It is used to raise an exception, manually.
`raise`
它用于手动引发异常。
```java
x="hello"
...
...
@@ -178,10 +211,19 @@ async def ping_server(ip):
```
|
| **错误** | 它是一个布尔值,与 0 相同。 |
| **正确** | 它是一个布尔值,与 1 相同。 |
| 的 | It is used to create a for loop. A for loop can be used to iterate through a sequence, like a list, tuple, etc.
`False`
它是一个布尔值,与 0 相同。
`True`
它是一个布尔值,与 1 相同。
`for`
它用于创建`for`循环。 `for`循环可用于遍历序列(如列表,元组等)。
```java
forxinrange(1,9):
...
...
@@ -189,8 +231,10 @@ async def ping_server(ip):
```
|
| **而** | It is used to create a while loop. The loop continues until the conditional statement is false.
`while`
它用于创建`while`循环。 循环继续进行,直到条件语句为假。
```java
x=0
...
...
@@ -201,8 +245,10 @@ async def ping_server(ip):
```
|
| **中断** | It is used to break out a for loop, or a while loop.
`break`
它用于中断`for`循环或`while`循环。
```java
i=1
...
...
@@ -215,8 +261,10 @@ async def ping_server(ip):
```
|
| **继续** | It is used to end the current iteration in a for loop (or a while loop), and continues to the next iteration.
`continue`
它用于在`for`循环(或`while`循环)中结束当前迭代,并继续进行下一个迭代。
```java
foriinrange(9):
...
...
@@ -226,22 +274,28 @@ async def ping_server(ip):
```
|
| 进口 | It is used to import modules.
`import`
它用于导入模块。
```java
importdatetime
```
|
| 中的 | It is used to import only a specified section from a module.
`from`
它仅用于从模块中导入指定的节。
```java
fromdatetimeimporttime
```
|
| **全局** | It is used to create global variables from a no-global scope, e.g. inside a function.
`global`
它用于从非全局范围创建全局变量,例如在函数内部。
```java
defmyfunction():
...
...
@@ -250,9 +304,12 @@ from datetime import time
```
|
| 中的 | 1\. It is used to check if a value is present in a sequence (list, range, string etc.).
2\. It is also used to iterate through a sequence in a `for` loop.
`in`
1\. 它用于检查序列(列表,范围,字符串等)中是否存在值。
2\. 它也用于在`for`循环中遍历序列。
```java
fruits=["apple","banana","cherry"]
...
...
@@ -265,8 +322,10 @@ from datetime import time
```
|
| **是** | It is used to test if two variables refer to the same object.
`is`
它用于测试两个变量是否引用同一对象。
```java
a=["apple","banana","cherry"]
...
...
@@ -278,8 +337,10 @@ from datetime import time
```
|
| **lambda** | It is used to create small anonymous functions. They can take any number of arguments, but can only have one expression.
`lambda`
它用于创建小的匿名函数。 它们可以接受任意数量的参数,但只能有一个表达式。
```java
x=lambdaa,b,c:a+b+c
...
...
@@ -288,9 +349,12 @@ from datetime import time
```
|
| **无** | It is used to define a `null` value, or no value at all. None is not the same as 0, False, or an empty string.
None is a datatype of its own (*NoneType*) and only None can be None.
`None`
它用于定义一个“空”值,或者根本没有值。 `None`与 0,`False`或空字符串不同。
`None`是它自己的数据类型(`NoneType`),并且只有`None`可以是`None`。
```java
x=None
...
...
@@ -302,8 +366,10 @@ None is a datatype of its own (*NoneType*) and only None can be None.
```
|
| **非本地** | It is used to declare that a variable is not local. It is used to work with variables inside nested functions, where the variable should not belong to the inner function.
`nonlocal`
它用于声明变量不是局部变量。 它用于在嵌套函数内部使用变量,其中变量不应属于内部函数。
```java
defmyfunc1():
...
...
@@ -318,8 +384,10 @@ None is a datatype of its own (*NoneType*) and only None can be None.
```
|
| **不是** | It is a logical operator and reverses the value of True or False.
`not`
它是一个逻辑运算符,并反转`True`或`False`的值。
```java
x=False
...
...
@@ -328,26 +396,35 @@ None is a datatype of its own (*NoneType*) and only None can be None.
```
|
| **通过** | It is used as a placeholder for future code. When the pass statement is executed, nothing happens, but you avoid getting an error when an empty code is not allowed.循环,函数定义,类定义或 if 语句中不允许使用空代码。