-
-
Notifications
You must be signed in to change notification settings - Fork 83
Description
Python Version
3.12+
Docs Page
https://docs.python.org/zh-cn/3.13/library/functions.html#complex
Original Translation
如果该参数为字符串,则它必须包含一个实部(使用与 float() 相同的格式)或一个虚部(使用相同的格式但带有 'j'
或 'J'
后缀),或者同时包含实部和虚部(在此情况下虚部必须加上正负号)。 该字符串首尾可以选择加上空格和圆括号 '('
and ')'
,它们将会被忽略。 该字符串的, which are ignored. The string must not contain whitespace between '+'
, '-'
, 'j'
或 'J'
后缀以及十进制数字之间不可包含空格。 例如,complex('1+2j')
是可以的,但 complex('1 + 2j')
则会引发 ValueError。 更准确地说,输入在移除圆括号以及开头和末尾的空格符之后,必须符合使用以下语法的 complexvalue 产生规则:
Original Docs Paragraph
If the argument is a string, it must contain either a real part (in the same format as for float()) or an imaginary part (in the same format but with a 'j'
or 'J'
suffix), or both real and imaginary parts (the sign of the imaginary part is mandatory in this case). The string can optionally be surrounded by whitespaces and the round parentheses '('
and ')'
, which are ignored. The string must not contain whitespace between '+'
, '-'
, the 'j'
or 'J'
suffix, and the decimal number. For example, complex('1+2j')
is fine, but complex('1 + 2j')
raises ValueError. More precisely, the input must conform to the complexvalue production rule in the following grammar, after parentheses and leading and trailing whitespace characters are removed:
Suggested Fix
此文本的问题自3.12版本文档加入该文本后一直存在,英文原文部分在翻译后未被正确删除。
以下翻译对原翻译的部分表述进行了改进,如原文的whitespaces
从空格
修正为空白字符
等。
如果该参数为字符串,则它必须包含一个实部(格式与 float() 接受的格式相同)或一个虚部(与实部格式相同,但带有 'j'
或 'J'
后缀),或者同时包含实部和虚部(在此情况下虚部必须加上正负号)。 该字符串可以被空白字符和圆括号 '('
和 ')'
包裹,但它们会被忽略。 该字符串中的 '+'
、 '-'
、 'j'
或 'J'
后缀与十进制数字之间不可存在空格。 例如,complex('1+2j')
是可以的,但 complex('1 + 2j')
则会引发 ValueError。 更准确地说,输入在移除圆括号以及首尾的空白字符之后,必须符合以下 complexvalue 产生式规则: