Python之33個(gè)關(guān)鍵字是:1、內(nèi)置常量【False、None、True】;2、邏輯與、或、非【and or not】;3、判斷與循環(huán)【if elif else,for while break continue】;4、重命名【as】。
【相關(guān)學(xué)習(xí)推薦:python教程】
Python之33個(gè)關(guān)鍵字是:
一、Python所有關(guān)鍵字查看
import keysword keyword.kwlist
['False','None', 'True','and','as', 'assert','break',
'class','continue', 'def','del','elif', 'else','except',
'finally', 'for', 'from','global','if','import','in','is',
'lambda', 'nonlocal','not','or','pass','raise', 'return',
'try','while','with','yield']
二、Python關(guān)鍵字詳解
1、內(nèi)置常量
False、None、True
>>> False == 0 True >>> True == 1 True >>> type(False) <class 'bool'> >>> type(None) <class 'NoneType'>
2、邏輯與 或 非 and or not
優(yōu)先級(jí):not and or
x and y 如果 x 為 False 、空、0,返 回 x,否則返回 y
x or y 如果 x 為 False、 空、0,返回 y,否則返回x
not x 如果 x 為 False、 空、0,返回 True,否則返回False
3、判斷 與 循環(huán)
if elif else
is in
for while break continue
4、函數(shù)
def lambda
pass return yied
5、異常處理
try except finally raise assert
6、導(dǎo)入模塊 包
import from
7、重命名
as
8、變量
global nonlocal
9、類
class
10、刪除
del
11、上下文管理
with
想了解