python 示例_带有示例的Python内置关键字

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.KeywordDescription
1andIt is used for logical operations, it is a logical AND operator. It returns "True" if both operands are True.
2asIt is used to create an alias of a module.
3assertIt is used for debugging purpose, it returns an "AssertionError" if the given test condition is False.
4breakbreak 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.
5classIt is used to define/create a class.
6continueIt leaves the rest of the statements in the loop body and continues the next iteration of the loop.
7defIt is used to define/create a function.
8delIt is used to delete an object.
9elifIt is used with "if...elif...else" statement to check next condition. It is the same as "else if" of C, C++ language.
10elseIt is used with "if...elif...else" statement to define an else block – if any condition is not True, else block executes.
11exceptJust 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.
12FalseIt is used to define a Boolean value False, it may also the result of a comparisons expression.
13finallyIt 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.
14forIt is used to create a for loop.
15fromIt is used to import a specific section (like functions, classes, etc) from a module.
16ifIt is used to create a conditional statement i.e. to check the condition.
17importIt is used to import a module in the program.
18inIt is used to check whether an element present in a sequence like string, list, tuple, etc.
19isIt is used to check whether two objects are the same objects or not.
20lambdaIt is used to create an anonymous function that can have multiple arguments but a single statement/expression.
21NoneIt is similar to the null, it is used to define a null value.
22nonlocalIt 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.
23notIt is a logical operator (logical NOT) and returns "True" if the operand is "False" or returns "False" if the operand is "True".
24orIt 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".
25passIt is used as a null statement, it is very useful to define a blank function or a blank body of a conditional statement.
26raiseIt is used to raise an error and displays a customized message.
27returnTo 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.
28TrueIt is used to define a Boolean value False, it may also the result of a comparisons expression.
29tryIt is used with "try...except...finally" block.
30whileIt is used to create a while loop.
31withIt is similar to "using" in C#.Net and VB.Net, it is used to simplify the exception handling.
32yieldIt 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 示例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值