diff --git a/docs/misc2/150.md b/docs/misc2/150.md index 424d8f9fe14ca4fbbed05e2ed5892154f6a297ec..f03de840e0b1507ed2a920a8d2f7d32331e8c43b 100644 --- a/docs/misc2/150.md +++ b/docs/misc2/150.md @@ -6,7 +6,9 @@ Python 中有 35 个关键字 - 下面列出了它们的用法。 -| **和** | A **logical AND** operator. Return `True` if both statements are `True`. +`and` + +A **logical AND** operator. Return `True` if both statements are `True`. ```java x = (5 > 3 and 5 < 10) @@ -14,8 +16,10 @@ Python 中有 35 个关键字 - 下面列出了它们的用法。 ``` - | -| **或** | A **logical OR** operator. Returns `True` if either of two statements is true. If both statements are false, the returns `False`. + +`or` + +逻辑或运算符。 如果两个语句中的任何一个为`True`,则返回`True`。 如果两个语句都为假,则返回`False`。 ```java x = (5 > 3 or 5 > 10) @@ -23,8 +27,10 @@ Python 中有 35 个关键字 - 下面列出了它们的用法。 ``` - | -| **作为** | It is used to create an alias. + +`as` + +它用于创建别名。 ```java import calendar as c @@ -32,8 +38,10 @@ Python 中有 35 个关键字 - 下面列出了它们的用法。 ``` - | -| **断言** | It can be used for debugging the code. It tests a condition and returns `True` , if not, the program will raise an AssertionError. + +`assert` + +它可以用于调试代码。 它会测试条件并返回`True`,否则产生`AssertionError`。 ```java x = "hello" @@ -42,15 +50,19 @@ Python 中有 35 个关键字 - 下面列出了它们的用法。 ``` - | -| **异步** | It is used to declare a function as a coroutine, much like what the `@asyncio.coroutine` decorator does. + +`async` + +它用来声明一个函数为协程,就像`@asyncio.coroutine`装饰器所做的一样。 ```java async def ping_server(ip): ``` - | -| **等待** | It is used to call `async` coroutine. + +`await` + +它用于调用`async`协程。 ```java async def ping_local(): @@ -58,8 +70,10 @@ async def ping_server(ip): ``` - | -| **类** | It is used to create a class. + +`class` + +它用于创建一个类。 ```java class User: @@ -68,8 +82,10 @@ async def ping_server(ip): ``` - | -| **def** | It is used to create or define a function. + +`def` + +它用于创建或定义函数。 ```java def my_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. + +`del` + +它用于删除对象。 在 Python 中,所有事物都是对象,因此`del`关键字也可以用于删除变量,[列表](https://howtodoinjava.com/python/python-lists/)或列表的一部分,等等。 ```java x = "hello" @@ -89,8 +107,10 @@ async def ping_server(ip): ``` - | -| 如果为 | 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 for x in range(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 for i in range(9): @@ -226,22 +274,28 @@ async def ping_server(ip): ``` - | -| 进口 | It is used to import modules. + +`import` + +它用于导入模块。 ```java import datetime ``` - | -| 中的 | It is used to import only a specified section from a module. + +`from` + +它仅用于从模块中导入指定的节。 ```java from datetime import time ``` - | -| **全局** | It is used to create global variables from a no-global scope, e.g. inside a function. + +`global` + +它用于从非全局范围创建全局变量,例如在函数内部。 ```java def myfunction(): @@ -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 = lambda a, 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 def myfunc1(): @@ -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 语句中不允许使用空代码。 + +`pass` + +它用作将来代码的占位符。 当执行`pass`语句时,什么也不会发生,但是当不允许使用空代码时,可以避免出现错误。循环,函数定义,类定义或`if`语句中不允许使用空代码。 ```java for x in [0, 1, 2]: pass ``` - | -| **返回** | It is to exit a function and return a value. + +`return` + +它是退出一个函数并返回一个值。 ```java def myfunction(): return 3+3 ``` - | -| **与** | 用于简化异常处理 | -| **产量** | 要结束一个函数,返回一个生成器 | + +`as` + +用于简化异常处理 + +`yield` + +要结束一个函数,返回一个生成器 学习愉快! -参考: [W3 学校](https://www.w3schools.com/python/python_ref_keywords.asp) \ No newline at end of file +参考: [W3School](https://www.w3schools.com/python/python_ref_keywords.asp) \ No newline at end of file