Skip to content

Commit 9f33cb8

Browse files
ducheng暮晨
ducheng
authored and
暮晨
committed
EX.+= is faster
1 parent a6c73ca commit 9f33cb8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ So, here we go...
7676
- [> Inpinity/无限 *](#-inpinity无限-)
7777
- [> Mangling time!修饰时间! *](#-mangling-time修饰时间-)
7878
- [Section: Miscellaneous](#section-miscellaneous)
79-
- [> `+=` is faster](#--is-faster)
79+
- [> `+=` is faster/更快的 `+=` ](#--is-faster更快的-)
8080
- [> Let's make a giant string!](#-lets-make-a-giant-string)
8181
- [> Explicit typecast of strings](#-explicit-typecast-of-strings)
8282
- [> Minor Ones](#-minor-ones)
@@ -2167,19 +2167,19 @@ True
21672167
## Section: Miscellaneous
21682168
21692169
2170-
### > `+=` is faster
2170+
### > `+=` is faster/更快的 `+=`
21712171
21722172
```py
2173-
# using "+", three strings:
2173+
# "+" 连接三个字符串:
21742174
>>> timeit.timeit("s1 = s1 + s2 + s3", setup="s1 = ' ' * 100000; s2 = ' ' * 100000; s3 = ' ' * 100000", number=100)
21752175
0.25748300552368164
2176-
# using "+=", three strings:
2176+
# "+=" 连接三个字符串:
21772177
>>> timeit.timeit("s1 += s2 + s3", setup="s1 = ' ' * 100000; s2 = ' ' * 100000; s3 = ' ' * 100000", number=100)
21782178
0.012188911437988281
21792179
```
21802180
2181-
#### 💡 Explanation:
2182-
+ `+=` is faster than `+` for concatenating more than two strings because the first string (example, `s1` for `s1 += s2 + s3`) is not destroyed while calculating the complete string.
2181+
#### 💡 说明:
2182+
+ 连接两个以上的字符串时 `+=` `+` 更快, 因为在计算过程中第一个字符串 (例如, `s1 += s2 + s3` 中的 `s1`) 不会被销毁.(译: 就是 `+=` 执行的是追加操作,少了一个销毁新建的动作.)
21832183
21842184
---
21852185

0 commit comments

Comments
 (0)