zoukankan      html  css  js  c++  java
  • 03 关键字?保留字?预留字?

    结论

    • 在 Python 中,不要多想,keyword 就是“关键字”

    • Python3.4 有 33 个关键字

    • Python3.7 有 35 个关键字

    • 官网中点击 What’s New In Python 3.7,查找 keywords 就能看到增加的两个关键字

      async and await are now reserved keywords

    查看

    方式一

    >>> help("keywords")
    
    Here is a list of the Python keywords.  Enter any keyword to get more help.
    
    False               class               from                or
    None                continue            global              pass
    True                def                 if                  raise
    and                 del                 import              return
    as                  elif                in                  try
    assert              else                is                  while
    async               except              lambda              with
    await               finally             nonlocal            yield
    break               for                 not                 
    
    >>> 
    >>> help(None)  # 三个大写开头的直接用 help 即可
    Help on NoneType object:
    
    class NoneType(object)
     |  Methods defined here:
     |  
     |  __bool__(self, /)
     |      self != 0
     |  
     |  __repr__(self, /)
     |      Return repr(self).
     |  
     |  ----------------------------------------------------------------------
     |  Static methods defined here:
     |  
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
    
    >>> 
    >>> help("break")  # 首字母非大写的需要先变成字符串,再 help
    The "break" statement
    *********************
    
       break_stmt ::= "break"
    
    "break" may only occur syntactically nested in a "for" or "while"
    loop, but not nested in a function or class definition within that
    loop.
    
    It terminates the nearest enclosing loop, skipping the optional "else"
    clause if the loop has one.
    
    If a "for" loop is terminated by "break", the loop control target
    keeps its current value.
    
    When "break" passes control out of a "try" statement with a "finally"
    clause, that "finally" clause is executed before really leaving the
    loop.
    
    Related help topics: while, for
    
    >>> 
    

    方式二

    >>> import keyword
    >>> keyword.kwlist
    ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', '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']
    >>> 
    

    补充

    • 对 Java 而言,“关键字”与“保留字”有所不同
      • goto, const 等是“保留字”但不是“关键字”
      • 简单地说,它们不能作为标识符,但也不是关键字
    • 这些“保留字”,就像有些电影公司买下 IP,自己不拍,别人也不能拍
    • 翻译关系,也有“预留字”的说法,有时候指关键字,有时候指保留字,视具体情况而定了
  • 相关阅读:
    合同主体列表添加两条合同主体,返回合并支付页面,支付总弹"请选择合同主体",删除后,竟然还能支付(改合并支付页面的字段状态)
    (TODO:)下载图片,报错:warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.
    GCD死锁 多线程
    iOS知识总结
    快速排序,冒泡排序,选择排序
    fight
    3D Touch
    Xcode 调试技巧
    右滑退出手势及隐藏导航栏存在的风险
    C语言-第5课
  • 原文地址:https://www.cnblogs.com/yorkyu/p/10306369.html
Copyright © 2011-2022 走看看