当应用于字符串格式时,%运算符的文档中是否有不正确的地方?

2024-06-02 06:46:51 发布

您现在位置:Python中文网/ 问答频道 /正文

Here是对旧式字符串格式的描述,其中规定了八进制和十六进制值的转换。 我已经尝试过语法,但是发生了一些意想不到的事情

代码'%#07x' % 1223'%#07o' % 1223的结果格式相似,分别为'0x004c7''0o02307'。但是,有关八进制值的相关描述与行为不匹配

The alternate form causes a leading zero ('0') to be inserted between left-hand padding and the formatting of the number if the leading character of the result is not already a zero.

所有代码都在CPython的交互式解释器中执行,版本为3.5.2


Tags: ofthe字符串代码formhere格式语法