变量定义规范与常量

声明变量

name = "Alex Li"

便令定义规则

变量名只能是字母、数字或下划线的任意组合。

变量名的第一个字符不能是数字

以下关键字不能声明为变量名[and,as,assert,break,class,continue,def,del,elif,else,except,exec,finall,for,from,global,if,import,in,is,lambda,not,or,pass,print,raise,return,try,while,with,yield]

变量命名习惯

驼峰体

AgeOfOldboy = 56

NumberOfStudents =80

下划线

age_of_oldboy =56

number_of_students =80

常量

常量即指不变的量,如pai3.141592653...,或程序运行过程中不会改变的量

在Python中没有一个专门的语法代表常量,程序员约定俗成用变量名全部大写代表常量

猜你喜欢

转载自www.cnblogs.com/mous/p/10241761.html
今日推荐