免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2816 | 回复: 0
打印 上一主题 下一主题

keyword-Testing for Python keywords [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-31 00:29 |只看该作者 |倒序浏览

                                keyword用来判断指定的字符串是否为关键字
keyword.iskeyword(s)Return true if s is a Python keyword.
keyword.kwlistSequence containing all the keywords defined for the interpreter.  If any
keywords are defined to only be active when particular __future__ statements are in effect, these will be included as well.
Example:
               
               
               
               
               
               
                Python 2.6.4 (r264:75706, Dec 31 2009, 07:25:24)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import keyword
>>> keyword.iskeyword('and')
True
>>> keyword.iskeyword('list')
False
>>> keyword.iskeyword('or')
True
>>> keyword.kwlist
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/109054/showart_2135983.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP