Chinaunix首页 | 论坛 | 博客
  • 博客访问: 207330
  • 博文数量: 32
  • 博客积分: 3319
  • 博客等级: 中校
  • 技术积分: 340
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-26 21:40
文章分类

全部博文(32)

文章存档

2010年(31)

2009年(1)

分类: Python/Ruby

2009-12-31 00:29:50

keyword用来判断指定的字符串是否为关键字
keyword.iskeyword(s)
Return true if s is a Python keyword.
keyword.kwlist
Sequence 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']


阅读(1622) | 评论(0) | 转发(0) |
0

上一篇:网易3月招聘会

下一篇:终端着色备忘

给主人留下些什么吧!~~