What is a format_map in Python

The German Python forum

Code: Select all

That must have been all the possibilities. For the format method, be sure to read this here: https://docs.python.org/3/library/strin ... matstrings
This also applies to format strings in Python 3.6.

As of Python 3.x, all strings are Unicode. The internal representation depends on the Python version.
Then there are bytes that explicitly represent the binary representation of memory.
For example, if you have opened a file in binary mode, the object to be written must also be explicitly bytes.
Fortunately, there has been no implicit conversion from str to bytes since Python 3.

str> bytes: encode> utf-8 by default
bytes> str: decode
Byte strings are marked with a b prefix in the program code.
b'Andre M \ xfcller '# encoded with latin1
b'Andre M \ xc3 \ xbcller '# encoded with utf-8

As can already be seen, characters that cannot be represented by ASCII are represented as \ xHEX.
Characters can also be entered explicitly in the program code. Valid in bytestrings is \ x00 - \ xFF.
This can also be used in strings. For 2 byte unicode \ u3ccc and for 4 byte unicode \ U
The best way to do this is to read the documentation on Unicode: https://docs.python.org/3/howto/unicode.html
Sometimes this can be a little confusing.

By the way, you can also enter variable names in Unicode in the program code to annoy others.

If you open files, they are opened in text mode by default and the encoding is utf-8.
If you open files in raw mode, bytes must also be written explicitly. You will surely stumble over this more often than not.