python的关键字操作_(Python基础教程之六)Python中的关键字

KeywordDescription

andA logical AND operator. Return True if both statements are True.

orA logical OR operator. Returns True if either of two statements is true. If both statements are false, the returns False.

asIt is used to create an alias.

assertIt can be used for debugging the code. It tests a condition and returns True , if not, the program will raise an AssertionError.

asyncIt is used to declare a function as a coroutine, much like what the @asyncio.coroutine decorator does.

awaitIt is used to call async coroutine.

classIt is used to create a class.

defIt is used to create or define a function.

delIt 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.

ifIt is used to create conditional statements that allows us to execute a block of code only if a condition is True.

elifIt is used in conditional statements and is short for else if.

elseIt decides what to do if the condition is False in if..else statement.

It can also be use in try...except blocks.

tryIt defines a block of code ot test if it contains any errors.

exceptIt defines a block of code to run if the try block raises an error.

finallyIt defines a code block which will be executed no matter if the try block raises an error or not.

raiseIt is used to raise an exception, manually.

FalseIt is a Boolean value and same as 0.

TrueIt is a Boolean value and same as 1.

forIt is used to create a for loop. A for loop can be used to iterate through a sequence, like a list, tuple, etc.

whileIt is used to create a while loop. The loop continues until the conditional statement is false.

breakIt is used to break out a for loop, or a while loop.

continueIt is used to end the current iteration in a for loop (or a while loop), and continues to the next iteration.

importIt is used to import modules.

fromIt is used to import only a specified section from a module.

globalIt is used to create global variables from a no-global scope, e.g. inside a function.

in1. 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.

isIt is used to test if two variables refer to the same object.

lambdaIt is used to create small anonymous functions. They can take any number of arguments, but can only have one expression.

NoneIt 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.

nonlocalIt 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.

notIt is a logical operator and reverses the value of True or False.

passIt 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.

returnIt is to exit a function and return a value.

withUsed to simplify exception handling

yieldTo end a function, returns a generator

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值