变量

官方定义:

  Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.

  变量的作用是存储在计算机中被引用和操作的信息,他们同样提供了一种用可描述性名字来标记数据的方式,因此我们的程序可以更容易被读者和我们自己理解。将变量看作容纳信息的容器是有帮助的。他的核心目标是在内存中标记和存储数据,这个数据稍后会通过程序被调用。(读的顺的地方是有道词典,不顺的是本人手撸)

自我理解:

  变量就是一个容器,用来标记内存中存储的信息

  也供我们后续使用

  (我第一个编程老师说,其实学编程就是学容器)

变量命名

  一般来说,为了方便我们自己和他人阅读,我们尽量要使用一个有意义的名称来顶一个合格变量

  规则:

    YES:数字、字母下划线

    NO:特殊字符、空格、数字开头、保留字(关键字)

    注:python中,可以使用中文当做变量名,但是一般约定不要使用中文当做变量名,因为不利于走出国门走向世界

    驼峰命名:1)大驼峰ShoppingList;2)小驼峰shoppingList

    下划线链接:shopping_list

变量赋值

python为变量赋值时,不用声明变量类型

num = 1
s = "string"
isTrue = True

python可以同时为多个变量赋值 

>>> a, b = 1, 2.1

  

常量:

  python中,没有常量,所有的变量都是可变的

  我们约定,将使用全大写描述的变量名视为常量

原文地址:https://www.cnblogs.com/f0t1/p/12010789.html