15 变量的定义规范
声明变量:
变量定义规则
- 变量名只能是 字母、数字或下划线的任意组合
- 变量名的第一个字符不能是数字
- 以下关键字不能声明为变量名['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']
1 SyntaxError: invalid syntax 2 >>> name!2 = 3 3 File "<stdin>", line 1 4 name!2 = 3 5 ^ 6 SyntaxError: invalid syntax 7 >>> name2 = 3 8 >>> name_2 = 3 9 >>> name_-2 = 3 10 File "<stdin>", line 1 11 SyntaxError: can't assign to operator 12 >>> name_ = 3 13 >>> _name_ = 3 14 >>> 3_name_ = 3 15 File "<stdin>", line 1 16 3_name_ = 3 17 ^ 18 SyntaxError: invalid token 19 >>> ddd_ name_ = 3 20 File "<stdin>", line 1 21 ddd_ name_ = 3 22 ^ 23 SyntaxError: invalid syntax
定义方式:
驼峰体
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。1 AgeOfOldboy = 56 2 NumberOfStudents = 80
下划线
1 age_of_oldboy = 56 2 number_of_students = 80

更多精彩