python 示例
Python关键字 (Python keywords)
Keywords are the reserved words in any programming language and their meanings/tasks are predefined, we cannot change their meanings.
关键字是任何编程语言中的保留字,它们的含义/任务是预定义的,我们无法更改其含义。
In python programming language, there are following python built-in keywords, which are used for various purposes to perform various tasks.
在python编程语言中 ,有以下python内置关键字 ,它们用于各种目的来执行各种任务。
所有python关键字的列表 (List of all python keywords)
Sr. | Keyword | Description |
---|---|---|
1 | and | It is used for logical operations, it is a logical AND operator. It returns "True" if both operands are True. |
2 | as | It is used to create an alias of a module. |
3 | assert | It is used for debugging purpose, it returns an "AssertionError" if the given test condition is False. |
4 | break | break the loop's execution. It is used to transfer program's control from a scope of loop body to the next statement written after the loop body. |
5 | class | It is used to define/create a class. |
6 | continue | It leaves the rest of the statements in the loop body and continues the next iteration of the loop. |
7 | def | It is used to define/create a function. |
8 | del | It is used to delete an object. |
9 | elif | It is used with "if...elif...else" statement to check next condition. It is the same as "else if" of C, C++ language. |
10 | else | It is used with "if...elif...else" statement to define an else block – if any condition is not True, else block executes. |
11 | except | Just like "catch" block in the other programming languages, it is used to define an "except" block that executes if any exception occurs in the try block. |
12 | False | It is used to define a Boolean value False, it may also the result of a comparisons expression. |
13 | finally | It is used with the exceptions block (try...except...finally), it defines a code block that executes always – not matter "try" block has an exception or not. |
14 | for | It is used to create a for loop. |
15 | from | It is used to import a specific section (like functions, classes, etc) from a module. |
16 | if | It is used to create a conditional statement i.e. to check the condition. |
17 | import | It is used to import a module in the program. |
18 | in | It is used to check whether an element present in a sequence like string, list, tuple, etc. |
19 | is | It is used to check whether two objects are the same objects or not. |
20 | lambda | It is used to create an anonymous function that can have multiple arguments but a single statement/expression. |
21 | None | It is similar to the null, it is used to define a null value. |
22 | nonlocal | It is used to declare a non-local variable, by using this keyword, we can instruct the compiler that the variable is not a local variable. |
23 | not | It is a logical operator (logical NOT) and returns "True" if the operand is "False" or returns "False" if the operand is "True". |
24 | or | It is a logical operator (logical OR), it is used to combine two conditions and returns "True" if any condition is "True", else it returns "False". |
25 | pass | It is used as a null statement, it is very useful to define a blank function or a blank body of a conditional statement. |
26 | raise | It is used to raise an error and displays a customized message. |
27 | return | To return a value or/and returns the program's control from calling a function to called function i.e. it is used to exit from the function. |
28 | True | It is used to define a Boolean value False, it may also the result of a comparisons expression. |
29 | try | It is used with "try...except...finally" block. |
30 | while | It is used to create a while loop. |
31 | with | It is similar to "using" in C#.Net and VB.Net, it is used to simplify the exception handling. |
32 | yield | It is used to end a function and returns a generator. |
高级 | 关键词 | 描述 |
---|---|---|
1个 | 和 | 它用于逻辑运算,它是逻辑AND运算符。 如果两个操作数均为True,则返回“ True”。 |
2 | 如 | 它用于创建模块的别名。 |
3 | 断言 | 它用于调试目的,如果给定的测试条件为False,它将返回“ AssertionError”。 |
4 | 打破 | 中断循环的执行。 它用于将程序的控制权从循环主体的范围转移到在循环主体之后编写的下一条语句。 |
5 | 类 | 它用于定义/创建一个类。 |
6 | 继续 | 它将其余的语句留在循环主体中,并继续循环的下一个迭代。 |
7 | 定义 | 它用于定义/创建函数。 |
8 | 德尔 | 用于删除对象。 |
9 | 小精灵 | 它与“ if ... elif ... else”语句一起使用以检查下一个条件。 与C,C ++语言的“ else if”相同。 |
10 | 其他 | 它与“ if ... elif ... else”语句一起使用以定义else块–如果任何条件不为True,则执行else块。 |
11 | 除 | 就像其他编程语言中的“ catch”块一样,它用于定义“ except”块,如果try块中发生任何异常,则执行该“ except”块。 |
12 | 假 | 它用于定义布尔值False,也可以是比较表达式的结果。 |
13 | 最后 | 它与异常块(try ... except ... finally)一起使用,它定义了始终执行的代码块-不管“ try”块是否存在异常。 |
14 | 对于 | 它用于创建for循环。 |
15 | 从 | 它用于从模块中导入特定部分(如函数,类等)。 |
16 | 如果 | 它用于创建条件语句,即检查条件。 |
17 | 进口 | 它用于在程序中导入模块。 |
18 | 在 | 它用于检查元素是否按序列出现,例如字符串,列表,元组等。 |
19 | 是 | 用于检查两个对象是否相同。 |
20 | 拉姆达 | 它用于创建一个匿名函数,该函数可以有多个参数,但只有一个语句/表达式。 |
21 | 没有 | 它类似于null,用于定义null值。 |
22 | 非本地 | 它用于声明非局部变量,通过使用此关键字,我们可以指示编译器该变量不是局部变量。 |
23 | 不 | 它是逻辑运算符(逻辑非),如果操作数为“ False”,则返回“ True”;如果操作数为“ True”,则返回“ False”。 |
24 | 要么 | 它是逻辑运算符(逻辑或),用于组合两个条件,如果任何条件为“ True”,则返回“ True”,否则返回“ False”。 |
25 | 通过 | 它用作空语句,定义条件语句的空白函数或空白正文非常有用。 |
26 | 提高 | 它用于引发错误并显示自定义消息。 |
27 | 返回 | 要返回一个值或/和使程序的控制从调用函数返回到被调用函数,即,它用于退出该函数。 |
28 | 真正 | 它用于定义布尔值False,也可以是比较表达式的结果。 |
29 | 尝试 | 它与“ try ... except ... finally”块一起使用。 |
30 | 而 | 它用于创建while循环。 |
31 | 与 | 它类似于C#.Net和VB.Net中的“使用”,用于简化异常处理。 |
32 | 让 | 它用于结束函数并返回生成器。 |
This is the complete list of python keywords; you can read the detailed explanation with keyword task, syntax, example, etc of any keyword by clicking on the link.
这是python关键字的完整列表 ; 您可以通过单击链接阅读任何关键字的关键字任务,语法,示例等的详细说明。
翻译自: https://www.includehelp.com/python/built-in-keywords-with-examples.aspx
python 示例