zoukankan      html  css  js  c++  java
  • Python基础学习之标识符

    1、合法的Python标识符

      Python标识符字符串规则和其他大部分用C编写的高级语言相似:

    • 第一个字符必须是字母或下划线(_)
    • 剩下的字符可以是字母和数字或下滑线
    • 大小写敏感

      标识符不能以数字开头;除了下划线,其他的符号都不允许使用。

    2、关键字

    1 >>> import keyword
    2 >>> print(keyword.kwlist)
    3 ['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']

     3、专用下划线标识符

       Python用下划线作为变量前缀和后缀制定特殊变量。

    • 一般来讲_xxx被看做是私有的,在模块或类外不可以使用。
    • __xxx__ 系统定义名字
    • __ 类中私有变量名。

       避免用下划线做为变量名的开始!

  • 相关阅读:
    3.28
    03.21
    03.16
    03.15
    03.14小记
    [LC] 96. Unique Binary Search Trees
    [LC] 298. Binary Tree Longest Consecutive Sequence
    [LC] 102. Binary Tree Level Order Traversal
    [LC] 107. Binary Tree Level Order Traversal II
    [LC] 513. Find Bottom Left Tree Value
  • 原文地址:https://www.cnblogs.com/me80/p/6824346.html
Copyright © 2011-2022 走看看