变量与常量

变量的定义规范
1、变量名只能是字母、数字或下划线的任意组合
2、变量名的第一个字符不能是数字
3、以下关键字不能声明变量名 ['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']

变量的定义方式
驼峰体
AgeOfOldboy=56
NuberOfStudents=80
 
 
x
 
 
 
1
AgeOfOldboy=56
 
 
2
NuberOfStudents=80
 
 
下划线
age_of_oldboy=56
nuber_of_students=80
 
 
 
1
 
 
1
age_of_oldboy=56
 
 
2
nuber_of_students=80
 
 
变量定义LOW的方式
1、变量名为中文、拼音
2、变量名过长
3、变量名词不达意
 
常量
常量即指不变的量,如pai 3.141592653..,或在程序运行过程中不会改变的量
在Python中没有一个专门的语法代表常量,程序员约定俗成用变量名全部大写代表常量
AGE_OF_OLDBOY=56
 
 
1
 
 
 
 
 
1
AGE_OF_OLDBOY=56
 
 
在c语方中有专门的常量定义语法,const int conut =60;一量定义为常量,更改即会报错
 

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">





猜你喜欢

转载自www.cnblogs.com/yjiu1990/p/8962288.html