Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(c02_p15): typo #374

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/c02/p15_interpolating_variables_in_strings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ Python并没有对在字符串中简单替换变量值提供直接的支持。
>>>

然而, ``format()`` 和 ``format_map()`` 相比较上面这些方案而已更加先进,因此应该被优先选择。
使用 ``format()`` 方法还有一个好处就是你可以获得对字符串格式化的所有支持(对齐,填充,数字格式化等待),
使用 ``format()`` 方法还有一个好处就是你可以获得对字符串格式化的所有支持(对齐,填充,数字格式化等等),
而这些特性是使用像模板字符串之类的方案不可能获得的。

本机还部分介绍了一些高级特性。映射或者字典类中鲜为人知的 ``__missing__()`` 方法可以让你定义如何处理缺失的值。
本节还部分介绍了一些高级特性。映射或者字典类中鲜为人知的 ``__missing__()`` 方法可以让你定义如何处理缺失的值。
在 ``SafeSub`` 类中,这个方法被定义为对缺失的值返回一个占位符。
你可以发现缺失的值会出现在结果字符串中(在调试的时候可能很有用),而不是产生一个 ``KeyError`` 异常。

Expand Down