标识符是一些事物的名称和符号。
有如下规则:
严格区分大小写。
可以使用数字、字母、下划线。但不能以数字开头。
见名知意。
不能以关键字进行命名。
注意:
• 不能以特殊字符开头。
• 以下划线开头的标识符具有特殊含义,尽量避免使用这类标识符命名。
python关键字如下:
False class from or
None continue global pass
True def if raise
and del import return
as elif in try
assert else is while
async except lambda with
await finally nonlocal yield
break for not示例:
合法标识符:
test_1
Test_1
UserName
User1不合法标识符:
1test # 不能以数字开头
class # 不能使用关键字
$test # 不能以特殊符号开头问题:
以下命名不符合标识符规则的有?(多选)
A. list=[1,2,3,4]
B. 01_a=1
C. name = 'amy'
D. 年龄=18
回答:AB
注意:约定俗成的是,虽然中文可以作为标识符命名,但尽量不采用这种命名方式。


Comments | NOTHING