Skip to content

Commit cc4da5f

Browse files
ducheng暮晨
ducheng
authored and
暮晨
committed
EX.+= is faster
1 parent 48952e8 commit cc4da5f

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)
@@ -2166,19 +2166,19 @@ True
21662166
## Section: Miscellaneous
21672167
21682168
2169-
### > `+=` is faster
2169+
### > `+=` is faster/更快的 `+=`
21702170
21712171
```py
2172-
# using "+", three strings:
2172+
# "+" 连接三个字符串:
21732173
>>> timeit.timeit("s1 = s1 + s2 + s3", setup="s1 = ' ' * 100000; s2 = ' ' * 100000; s3 = ' ' * 100000", number=100)
21742174
0.25748300552368164
2175-
# using "+=", three strings:
2175+
# "+=" 连接三个字符串:
21762176
>>> timeit.timeit("s1 += s2 + s3", setup="s1 = ' ' * 100000; s2 = ' ' * 100000; s3 = ' ' * 100000", number=100)
21772177
0.012188911437988281
21782178
```
21792179
2180-
#### 💡 Explanation:
2181-
+ `+=` 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.
2180+
#### 💡 说明:
2181+
+ 连接两个以上的字符串时 `+=` `+` 更快, 因为在计算过程中第一个字符串 (例如, `s1 += s2 + s3` 中的 `s1`) 不会被销毁.(译: 就是 `+=` 执行的是追加操作,少了一个销毁新建的动作.)
21822182
21832183
---
21842184

0 commit comments

Comments
 (0)