@@ -3805,23 +3805,23 @@ msgstr ""
3805
3805
3806
3806
#: ../../library/stdtypes.rst:2338
3807
3807
msgid "Formatted String Literals (f-strings)"
3808
- msgstr ""
3808
+ msgstr "格式化字符串字面值(f-字符串) "
3809
3809
3810
3810
#: ../../library/stdtypes.rst:2341
3811
3811
msgid ""
3812
3812
"The :keyword:`await` and :keyword:`async for` can be used in expressions "
3813
3813
"within f-strings."
3814
- msgstr ""
3814
+ msgstr ":keyword:`await` 和 :keyword:`async for` 可在 f-字符串内部的表达式中使用。 "
3815
3815
3816
3816
#: ../../library/stdtypes.rst:2344
3817
3817
msgid "Added the debugging operator (``=``)"
3818
- msgstr ""
3818
+ msgstr "增加了调试运算符 (``=``) "
3819
3819
3820
3820
#: ../../library/stdtypes.rst:2346
3821
3821
msgid ""
3822
3822
"Many restrictions on expressions within f-strings have been removed. "
3823
3823
"Notably, nested strings, comments, and backslashes are now permitted."
3824
- msgstr ""
3824
+ msgstr "许多针对 f-字符串内部的表达式的限制已被移除。 例如,嵌套字符串、注释和反斜杠现在都是允许的。 "
3825
3825
3826
3826
#: ../../library/stdtypes.rst:2350
3827
3827
msgid ""
@@ -3832,6 +3832,9 @@ msgid ""
3832
3832
"evaluated at runtime, similarly to :meth:`str.format`, and are converted "
3833
3833
"into regular :class:`str` objects. For example:"
3834
3834
msgstr ""
3835
+ ":dfn:`f-字符串` (正式名称为 :dfn:`格式化字符串字面值`) 是带有 ``f`` 或 ``F`` 前缀的字符串字面值。 "
3836
+ "这种类型的字符串字面值允许将任意 Python 表达式嵌入到由花括号 (``{}``) 标记的 *替换字段* 内部。 这些表达式将在运行时被求值,这与 "
3837
+ ":meth:`str.format` 类似,并被转换为常规的 :class:`str` 对象。 例如:"
3835
3838
3836
3839
#: ../../library/stdtypes.rst:2358
3837
3840
msgid ""
@@ -3840,70 +3843,89 @@ msgid ""
3840
3843
">>> f'{who.title()} expects the {nationality} Inquisition!'\n"
3841
3844
"'Nobody expects the Spanish Inquisition!'"
3842
3845
msgstr ""
3846
+ ">>> who = 'nobody'\n"
3847
+ ">>> nationality = 'Spanish'\n"
3848
+ ">>> f'{who.title()} expects the {nationality} Inquisition!'\n"
3849
+ "'Nobody expects the Spanish Inquisition!'"
3843
3850
3844
3851
#: ../../library/stdtypes.rst:2365
3845
3852
msgid "It is also possible to use a multi line f-string:"
3846
- msgstr ""
3853
+ msgstr "也可以使用包含多行的 f-字符串: "
3847
3854
3848
3855
#: ../../library/stdtypes.rst:2367
3849
3856
msgid ""
3850
3857
">>> f'''This is a string\n"
3851
3858
"... on two lines'''\n"
3852
3859
"'This is a string\\ non two lines'"
3853
3860
msgstr ""
3861
+ ">>> f'''This is a string\n"
3862
+ "... on two lines'''\n"
3863
+ "'This is a string\\ non two lines'"
3854
3864
3855
3865
#: ../../library/stdtypes.rst:2373
3856
3866
msgid ""
3857
3867
"A single opening curly bracket, ``'{'``, marks a *replacement field* that "
3858
3868
"can contain any Python expression:"
3859
- msgstr ""
3869
+ msgstr "一个单独的左花括号,``'{'``,标记一个可包含任意 Python 表达式的 *替换字段*: "
3860
3870
3861
3871
#: ../../library/stdtypes.rst:2376
3862
3872
msgid ""
3863
3873
">>> nationality = 'Spanish'\n"
3864
3874
">>> f'The {nationality} Inquisition!'\n"
3865
3875
"'The Spanish Inquisition!'"
3866
3876
msgstr ""
3877
+ ">>> nationality = 'Spanish'\n"
3878
+ ">>> f'The {nationality} Inquisition!'\n"
3879
+ "'The Spanish Inquisition!'"
3867
3880
3868
3881
#: ../../library/stdtypes.rst:2382
3869
3882
msgid "To include a literal ``{`` or ``}``, use a double bracket:"
3870
- msgstr ""
3883
+ msgstr "要包括 ``{`` 或 ``}`` 字面值,请使用双花括号: "
3871
3884
3872
3885
#: ../../library/stdtypes.rst:2384
3873
3886
msgid ""
3874
3887
">>> x = 42\n"
3875
3888
">>> f'{{x}} is {x}'\n"
3876
3889
"'{x} is 42'"
3877
3890
msgstr ""
3891
+ ">>> x = 42\n"
3892
+ ">>> f'{{x}} is {x}'\n"
3893
+ "'{x} is 42'"
3878
3894
3879
3895
#: ../../library/stdtypes.rst:2390
3880
3896
msgid ""
3881
3897
"Functions can also be used, and :ref:`format specifiers <formatstrings>`:"
3882
- msgstr ""
3898
+ msgstr "还可以使用函数,以及 :ref:`格式说明符 <formatstrings>`: "
3883
3899
3884
3900
#: ../../library/stdtypes.rst:2392
3885
3901
msgid ""
3886
3902
">>> from math import sqrt\n"
3887
3903
">>> f'√2\\ N{ALMOST EQUAL TO} {sqrt(2):.5f}'\n"
3888
3904
"'√2 ≈ 1.41421'"
3889
3905
msgstr ""
3906
+ ">>> from math import sqrt\n"
3907
+ ">>> f'√2\\ N{ALMOST EQUAL TO} {sqrt(2):.5f}'\n"
3908
+ "'√2 ≈ 1.41421'"
3890
3909
3891
3910
#: ../../library/stdtypes.rst:2398
3892
3911
msgid "Any non-string expression is converted using :func:`str`, by default:"
3893
- msgstr ""
3912
+ msgstr "在默认情况下,任何非字符串表达式都将使用 :func:`str` 来转换: "
3894
3913
3895
3914
#: ../../library/stdtypes.rst:2400
3896
3915
msgid ""
3897
3916
">>> from fractions import Fraction\n"
3898
3917
">>> f'{Fraction(1, 3)}'\n"
3899
3918
"'1/3'"
3900
3919
msgstr ""
3920
+ ">>> from fractions import Fraction\n"
3921
+ ">>> f'{Fraction(1, 3)}'\n"
3922
+ "'1/3'"
3901
3923
3902
3924
#: ../../library/stdtypes.rst:2406
3903
3925
msgid ""
3904
3926
"To use an explicit conversion, use the ``!`` (exclamation mark) operator, "
3905
3927
"followed by any of the valid formats, which are:"
3906
- msgstr ""
3928
+ msgstr "要使用显式转换,请使用 ``!`` (叹号) 运算符,后面跟任意的有效格式说明符,包括: "
3907
3929
3908
3930
#: ../../library/stdtypes.rst:2410 ../../library/stdtypes.rst:2578
3909
3931
#: ../../library/stdtypes.rst:3797
@@ -3912,27 +3934,27 @@ msgstr "转换符"
3912
3934
3913
3935
#: ../../library/stdtypes.rst:2412
3914
3936
msgid "``!a``"
3915
- msgstr ""
3937
+ msgstr "``!a`` "
3916
3938
3917
3939
#: ../../library/stdtypes.rst:2412
3918
3940
msgid ":func:`ascii`"
3919
3941
msgstr ":func:`ascii`"
3920
3942
3921
3943
#: ../../library/stdtypes.rst:2413
3922
3944
msgid "``!r``"
3923
- msgstr ""
3945
+ msgstr "``!r`` "
3924
3946
3925
3947
#: ../../library/stdtypes.rst:2413
3926
3948
msgid ":func:`repr`"
3927
3949
msgstr ":func:`repr`"
3928
3950
3929
3951
#: ../../library/stdtypes.rst:2414
3930
3952
msgid "``!s``"
3931
- msgstr ""
3953
+ msgstr "``!s`` "
3932
3954
3933
3955
#: ../../library/stdtypes.rst:2414
3934
3956
msgid ":func:`str`"
3935
- msgstr ""
3957
+ msgstr ":func:`str` "
3936
3958
3937
3959
#: ../../library/stdtypes.rst:2417
3938
3960
msgid "For example:"
@@ -3949,6 +3971,14 @@ msgid ""
3949
3971
">>> print(f'{question!a}')\n"
3950
3972
"'\\ xbfD\\ xf3nde est\\ xe1 el Presidente?'"
3951
3973
msgstr ""
3974
+ ">>> from fractions import Fraction\n"
3975
+ ">>> f'{Fraction(1, 3)!s}'\n"
3976
+ "'1/3'\n"
3977
+ ">>> f'{Fraction(1, 3)!r}'\n"
3978
+ "'Fraction(1, 3)'\n"
3979
+ ">>> question = '¿Dónde está el Presidente?'\n"
3980
+ ">>> print(f'{question!a}')\n"
3981
+ "'\\ xbfD\\ xf3nde est\\ xe1 el Presidente?'"
3952
3982
3953
3983
#: ../../library/stdtypes.rst:2430
3954
3984
msgid ""
@@ -3957,6 +3987,8 @@ msgid ""
3957
3987
" within the brackets, and can be used with a converter. By default, the "
3958
3988
"debugging operator uses the :func:`repr` (``!r``) conversion. For example:"
3959
3989
msgstr ""
3990
+ "在调试期间同时看到表达式和值会很有帮助,具体是在表达式后使用等号 (``=``)。 这将保留花括号内部的空格,并可以使用转换器。 "
3991
+ "在默认情况下,调试运算符使用 :func:`repr` (``!r``) 转换器。 例如:"
3960
3992
3961
3993
#: ../../library/stdtypes.rst:2436
3962
3994
msgid ""
@@ -3969,6 +4001,14 @@ msgid ""
3969
4001
">>> f'{calculation = !s}'\n"
3970
4002
"'calculation = 1/3'"
3971
4003
msgstr ""
4004
+ ">>> from fractions import Fraction\n"
4005
+ ">>> calculation = Fraction(1, 3)\n"
4006
+ ">>> f'{calculation=}'\n"
4007
+ "'calculation=Fraction(1, 3)'\n"
4008
+ ">>> f'{calculation = }'\n"
4009
+ "'calculation = Fraction(1, 3)'\n"
4010
+ ">>> f'{calculation = !s}'\n"
4011
+ "'calculation = 1/3'"
3972
4012
3973
4013
#: ../../library/stdtypes.rst:2447
3974
4014
msgid ""
@@ -3980,6 +4020,9 @@ msgid ""
3980
4020
"formatted result is then used as the final value for the replacement field. "
3981
4021
"For example:"
3982
4022
msgstr ""
4023
+ "输出一旦已被求值,就可以用 :ref:`格式说明符 <formatstrings>` 后面跟一个冒号 (``':'``) 来格式化它。 "
4024
+ "在表达式已被求值,并可能被转换为字符串之后,就会调用结果的 :meth:`!__format__` "
4025
+ "方法并附带该格式说明符,或者如果未给出格式说明符则附带空字符串。 随后将使用已格式化的结果作为替换字段最终的值。 例如:"
3983
4026
3984
4027
#: ../../library/stdtypes.rst:2455
3985
4028
msgid ""
@@ -3989,6 +4032,11 @@ msgid ""
3989
4032
">>> f'{Fraction(1, 7):_^+10}'\n"
3990
4033
"'___+1/7___'"
3991
4034
msgstr ""
4035
+ ">>> from fractions import Fraction\n"
4036
+ ">>> f'{Fraction(1, 7):.6f}'\n"
4037
+ "'0.142857'\n"
4038
+ ">>> f'{Fraction(1, 7):_^+10}'\n"
4039
+ "'___+1/7___'"
3992
4040
3993
4041
#: ../../library/stdtypes.rst:2467
3994
4042
msgid "``printf``-style String Formatting"
@@ -9686,15 +9734,15 @@ msgstr "str.splitlines 方法"
9686
9734
9687
9735
#: ../../library/stdtypes.rst:2323
9688
9736
msgid "! formatted string literal"
9689
- msgstr ""
9737
+ msgstr "! 格式化字符串字面值 "
9690
9738
9691
9739
#: ../../library/stdtypes.rst:2323
9692
9740
msgid "formatted string literals"
9693
- msgstr ""
9741
+ msgstr "格式化字符串字面值 "
9694
9742
9695
9743
#: ../../library/stdtypes.rst:2323
9696
9744
msgid "! f-string"
9697
- msgstr ""
9745
+ msgstr "! f-字符串 "
9698
9746
9699
9747
#: ../../library/stdtypes.rst:2323
9700
9748
msgid "f-strings"
@@ -9726,7 +9774,7 @@ msgstr "格式字符串字面值形式"
9726
9774
9727
9775
#: ../../library/stdtypes.rst:2323
9728
9776
msgid "! (exclamation mark)"
9729
- msgstr ""
9777
+ msgstr "! (叹号) "
9730
9778
9731
9779
#: ../../library/stdtypes.rst:2323
9732
9780
msgid ": (colon)"