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

What are the legal identifier requirements for python

hzc
Release: 2020-07-02 13:57:11
Original
13548 people have browsed it

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 "<stdin>", line 1
    2bin=2
       ^
SyntaxError: invalid syntax
Copy after login

2. Cannot contain illegal characters

>>> ssd@f=1
  File "<stdin>", line 1
    ssd@f=1
       ^
SyntaxError: invalid syntax
Copy after login

3. Numbers cannot be used as identifiers Symbol

>>> 123=&#39;wdsa&#39;
SyntaxError: can&#39;t assign to literal
Copy after login

4. Cannot contain spaces

>>> fds fds=1
  File "<stdin>", line 1
    fds fds=1
          ^
SyntaxError: invalid syntax
Copy after login

5. Cannot contain operators

>>> sdf+sdf=1
SyntaxError: can&#39;t assign to operator
6.python保留关键字不能作为标识符
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template