Home>Article>Backend Development> What are the legal identifier requirements for python

What are the legal identifier requirements for python

hzc
hzc Original
2020-07-02 13:57:11 13412browse

Python legal identifier requirements are: 1. It cannot start with a number; 2. It cannot contain illegal characters; 3. Numbers cannot be used as identifiers; 4. It cannot contain spaces; 5. It cannot contain operators.

What are the legal identifier requirements for python

1. Cannot start with a number

>>> 2bin=2 File "", line 1 2bin=2 ^ SyntaxError: invalid syntax

2. Cannot contain illegal characters

>>> ssd@f=1 File "", line 1 ssd@f=1 ^ SyntaxError: invalid syntax

3. Numbers cannot be used as identifiers Symbol

>>> 123='wdsa' SyntaxError: can't assign to literal

4. Cannot contain spaces

>>> fds fds=1 File "", line 1 fds fds=1 ^ SyntaxError: invalid syntax

5. Cannot contain operators

>>> sdf+sdf=1 SyntaxError: can't assign to operator 6.python保留关键字不能作为标识符

Recommended tutorial: "Python Tutorial"

The above is the detailed content of What are the legal identifier requirements for python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn