1. 变量
  1. 作用:

    • 编写程序的目的就是将待处理的数据, 经过程序计算, 得出结果数据

    • 变量就是在程序运行过程中, 临时存储程序所需要计算的数据

  2. 定义:

    • 在程序中表现为一个唯一不重复的名字, 只需定义一个名字, 给这个名字变量赋值即可.

    • 注意: 变量意味着存储的数据是可以变化的

  3. 命名规范:

    • 只能由字母、下划线和数字组成,且数字不能开头

    • python中的标识符是区分大小写的

    • 变量名不能加引号

      1. 定义:Python语言中已经占用的具有特殊含义的符号(事先霸占好了)

      2. 查看关键字的方法

        • 使用help("keywords")

        In [2]: help("keywords")
        
        Here is a list of the Python keywords.  Enter any keyword to get more help.
        
        False               def                 if                  raise
        None                del                 import              return
        True                elif                in                  try
        and                 else                is                  while
        as                  except              lambda              with
        assert              finally             nonlocal            yield
        break               for                 not                 
        class               from                or                  
        continue            global              pass                

        不能和关键字及已有的名字冲突

  4. 命名方法:

    • 大驼峰

      • XiaoMing

    • 小驼峰

      • xiaoMing

    • 下划线分隔法

      • xiao_ming

本文原创地址:https://www.linuxprobe.com/python-base-var.html编辑:问题终结者,审核员:逄增宝