Example analysis of Python's keyword module usage

Source: Internet
Author: User
This example describes Python's keyword module usage. Share to everyone for your reference. Specific as follows:

Help on Module Keyword:name  keyword-keywords (from "graminit.c") FILE  /usr/lib64/python2.6/ Keyword.pydescription This  file is automatically generated, please don ' t muck it up!  To update the symbols in this file, ' CDs ' to the top directory of the  Python source tree after building the interpreter and run:    python lib/keyword.pyfunctions  iskeyword = __contains__ (...)    X.__contains__ (y)  y in x.data  __all__ = [' Iskeyword ', ' kwlist ']  kwlist = [' and ', ' as ', ' assert ', ' break ', ' C ' Lass ', ' Continue ', ' def ', ...


Get a list of Python keywords:

>>> keyword.kwlist[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' from ', ' global ', ' if ', ' Import ', ' on ', ' is ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' R ' Eturn ', ' Try ', ' while ', ' with ', ' yield ' to determine if the string is a python keyword
>>> Keyword.iskeyword (' and ') true>>> >>> keyword.iskeyword (' has ') False


The above is the Python keyword module Usage example analysis content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.