当前位置:
首页 > temp > 简明python教程 >
-
Python中的关键字
Python关键字是python编程语言的保留字。这些关键字不能用于其他目的。
Python中有35个关键字-下面列出了它们的用法。
Keyword | Description | ||
---|---|---|---|
and |
A logical AND operator. Return True if both statements are True .
|
||
or |
A logical OR operator. Returns True if either of two statements is true. If both statements are false, the returns False .
|
||
as |
It is used to create an alias.
|
||
assert |
It can be used for debugging the code. It tests a condition and returns True , if not, the program will raise an AssertionError.
|
||
async |
It is used to declare a function as a coroutine, much like what the @asyncio.coroutine decorator does.
|
||
await |
It is used to call async coroutine.
|
||
class |
It is used to create a class.
|
||
def |
It is used to create or define a function.
|
||
del |
It is used to delete objects. In Python everything is an object, so the del keyword can also be used to delete variables, lists, or parts of a list, etc.
|
||
if |
It is used to create conditional statements that allows us to execute a block of code only if a condition is True .
|
||
elif |
It is used in conditional statements and is short for else if .
|
||
else |
It decides what to do if the condition is False in if..else statement.
It can also be use in
|
||
try | It defines a block of code ot test if it contains any errors. | ||
except |
It defines a block of code to run if the try block raises an error.
|
||
finally |
It defines a code block which will be executed no matter if the try block raises an error or not.
|
||
raise |
It is used to raise an exception, manually.
|
||
False | It is a Boolean value and same as 0. | ||
True | It is a Boolean value and same as 1. | ||
for |
It is used to create a for loop. A for loop can be used to iterate through a sequence, like a list, tuple, etc.
|
||
while |
It is used to create a while loop. The loop continues until the conditional statement is false.
|
||
break |
It is used to break out a for loop, or a while loop.
|
||
continue |
It is used to end the current iteration in a for loop (or a while loop), and continues to the next iteration.
|
||
import |
It is used to import modules.
|
||
from |
It is used to import only a specified section from a module.
|
||
global |
It is used to create global variables from a no-global scope, e.g. inside a function.
|
||
in |
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.
|
||
is |
It is used to test if two variables refer to the same object.
|
||
lambda |
It is used to create small anonymous functions. They can take any number of arguments, but can only have one expression.
|
||
None |
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.
|
||
nonlocal |
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.
|
||
not |
It is a logical operator and reverses the value of True or False.
|
||
pass |
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.
Empty code is not allowed in loops, function definitions, class definitions, or in if statements.
|
||
return |
It is to exit a function and return a value.
|
||
with | Used to simplify exception handling | ||
yield | To end a function, returns a generator |
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
关于JS定时器的整理
JS中使用Promise.all控制所有的异步请求都完
js中字符串的方法
import-local执行流程与node模块路径解析流程
检测数据类型的四种方法
js中数组的方法,32种方法
前端操作方法
数据类型
window.localStorage.setItem 和 localStorage.setIte
如何完美解决前端数字计算精度丢失与数