2. Lexical analysis — Python 3.11.16 documentation

docs.python.org

Tin mới

Python Module Index

3.11.16 Documentation

The Python Language Reference

2.1. Line structure¶

A Python program is read by a parser. Input to the parser is a stream of tokens, generated by the lexical analyzer. This chapter describes how the lexical analyzer breaks a file into tokens.

Standard Encodings

If no encoding declaration is found, the default encoding is UTF-8. If the implicit or explicit encoding of a file is UTF-8, an initial UTF-8 byte-order mark (b’xefxbbxbf’) is ignored rather than being a syntax error.

unicodedata: Access the Unicode Database.

Identifiers (also referred to as names) are described by the following lexical definitions.

builtins: The module that provides the built-in namespace.

In a case pattern within a match statement, _ is a soft keyword that denotes a wildcard.

gettext: Multilingual internationalization services.

The name _ is often used in conjunction with internationalization; refer to the documentation for the gettext module for more information on this convention.

Special method names

Identifiers (Names)

Class-private names. Names in this category, when used within the context of a class definition, are re-written to use a mangled form to help avoid name clashes between “private” attributes of base and derived classes. S

2.4.1. String and Bytes literals¶

String literals are described by the following lexical definitions:

format specifier mini-language

A formatted string literal or f-string is a string literal that is prefixed with 'f' or 'F'. These strings may contain replacement fields, which are expressions delimited by curly braces {}. While other string literals a