Identifiers in Python are names used to identify variables, functions, classes, modules, and other objects. Identifiers can contain letters, numbers, and underscores (_), but they must start with a non-numeric character. The alphabet consists only of A–Z and a–z in the ISO-Latin character set.
Identifiers are case-sensitive, so FOO and foo are two different objects. Special symbols, such as $, %, @, etc., cannot be used in identifiers. In addition, words such as if, else, for, etc. are reserved words and cannot be used as identifiers. (Recommended learning:Python video tutorial)
The following table lists all reserved characters and their descriptions:
Identifiers that start or end with an underscore usually have special meaning. For example, an identifier starting with an underscore (such as _foo) cannot be imported using the from module import * statement. Identifiers preceded and followed by two underscores, such as __init__, are reserved for special methods. Identifiers preceded by two underscores, such as __bar, are used to implement class private attributes. In general, similar identifiers should be avoided.
For more Python related technical articles, please visit thePython Tutorialcolumn to learn!
Reserved words |
Description |
and |
is used for expression operations, logical AND Operation |
as |
for type conversion |
assert |
Assertion, used to determine whether the value of a variable or conditional expression is true |
break |
Interrupt the execution of the loop statement |
Including the operation code after catching the exception, used in combination with try and finally |
|
is used to execute python statements |
|
Loop statement |
|
is used for exception statements. After an exception occurs, the code block contained in finally must always be executed. Used in combination with try and except |
|
is used to import modules, used in combination with import |
|
Define global variables |
|
Conditional statements, else, elif Used in combination with |
|
is used to import modules, used in combination with from |
|
Determine whether the variable exists in the sequence |
|
Determine whether the variable belongs to a certain class Example |
|
Define anonymous function |
|
Used for expression operations, logical NOT operations |
|
Used for expression operations, logical OR operations |
|
Placeholder for empty classes, functions, and methods |
|
Print statement |
|
Exception throwing operation |
|
Used to return calculation results from functions |
|
Contains may appear Exception statements, used in combination with except and finally |
|
Loop statement |
|
Simplified Python statements |
|
Used to return values from functions in sequence |
The above is the detailed content of Reserved words in python language. For more information, please follow other related articles on the PHP Chinese website!