We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1c46153 commit 567b71eCopy full SHA for 567b71e
zh_CN/3-tips-on-numbers-and-strings.md
@@ -275,6 +275,24 @@ def main():
275
- Saw (2004)""")
276
```
277
278
+#### 大数字也可以变得更加可读
279
+
280
+Python 中的数字,可以通过在中间添加下划线来提高可读性
281
+([PEP515](https://www.python.org/dev/peps/pep-0515/),需要 Python3.6+)。
282
283
+比如:
284
285
+```
286
+>>> 10_000_000.0 # 以“千”为单位划分数字
287
+10000000.0
288
+>>> 0xCAFE_F00D # 16进制数字同样有效,4个一组更易读
289
+3405705229
290
+>>> 0b_0011_1111_0100_1110 # 二进制也有效
291
+16206
292
+>>> int('0b_1111_0000', 2) # 处理字符串的时候也会正确处理下划线
293
+240
294
295
296
### 3. 别忘了那些 “r” 开头的内建字符串函数
297
298
Python 的字符串有着非常多实用的内建方法,最常用的有 `.strip()`、`.split()` 等。这些内建方法里的大多数,处理起来的顺序都是从左往右。但是其中也包含了部分以 `r` 打头的**从右至左处理**的镜像方法。在处理特定逻辑时,使用它们可以让你事半功倍。
0 commit comments