Python keyword 模块 -- 学习笔记

本文档介绍了Python内置的关键字列表及其使用方法。提供了如何检查一个字符串是否为Python关键字的功能,并列出了所有Python关键字。

 

keyword 的帮助文档

>>> import keyword
>>> help(keyword)
Help on module keyword:

NAME
    keyword - Keywords (from "graminit.c")

DESCRIPTION
    This file is automatically generated; please don't muck it up!
    
    To update the symbols in this file, 'cd' to the top directory of
    the python source tree after building the interpreter and run:
    
        ./python Lib/keyword.py

FUNCTIONS
    iskeyword = __contains__(...) method of builtins.frozenset instance
        x.__contains__(y) <==> y in x.

DATA
    __all__ = ['iskeyword', 'kwlist']
    kwlist = ['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'cl...

FILE
    e:\program files\python34\lib\keyword.py

 

kwlist  --  Python 关键字列表

>>> 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']

 

iskeyword  --  判断字符串是否是 Python 关键字

>>> keyword.iskeyword('and')
True
>>> keyword.iskeyword('has')
False

 

转载于:https://www.cnblogs.com/zBinnny/p/2016-01-07_01.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值