PHP前端开发

python合法标识符要求是什么

百变鹏仔 1个月前 (01-22) #Python
文章标签 标识符
python合法标识符要求是:1、不能以数字开头;2、不能包含非法字符;3、数字不能作为标识符;4、不能包含空格;5、不能包含运算符。

1.不能以数字开头

&gt;&gt;&gt; 2bin=2  File "<stdin>", line 1    2bin=2       ^SyntaxError: invalid syntax</stdin>

2.不能包含非法字符

&gt;&gt;&gt; ssd@f=1  File "<stdin>", line 1    ssd@f=1       ^SyntaxError: invalid syntax</stdin>

3.数字不能作为标识符

&gt;&gt;&gt; 123='wdsa'SyntaxError: can't assign to literal

4.不能包含空格

立即学习“Python免费学习笔记(深入)”;

&gt;&gt;&gt; fds fds=1  File "<stdin>", line 1    fds fds=1          ^SyntaxError: invalid syntax</stdin>

5.不能包含运算符

&gt;&gt;&gt; sdf+sdf=1SyntaxError: can't assign to operator6.python保留关键字不能作为标识符

推荐教程: 《python-tutorials.html" target="_blank">Python教程》