You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-20Lines changed: 20 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,7 @@ So, here we go...
79
79
-[> `+=` is faster/更快的 `+=`](#--is-faster更快的-)
80
80
-[> Let's make a giant string!/来做个巨大的字符串吧!](#-lets-make-a-giant-string来做个巨大的字符串吧)
81
81
-[> Explicit typecast of strings/字符串的显式类型转换](#-explicit-typecast-of-strings字符串的显式类型转换)
82
-
-[> Minor Ones](#-minor-ones)
82
+
-[> Minor Ones/小知识点](#-minor-ones小知识点)
83
83
-[Contributing](#contributing)
84
84
-[Acknowledgements](#acknowledgements)
85
85
-[🎓 License](#🎓-license)
@@ -2306,19 +2306,19 @@ nan
2306
2306
2307
2307
---
2308
2308
2309
-
### > Minor Ones
2309
+
### > Minor Ones/小知识点
2310
2310
2311
-
* `join()` is a string operation instead of list operation. (sort of counter-intuitive at first usage)
2311
+
* `join()` 是一个字符串操作而不是列表操作. (第一次接触会觉得有点违反直觉)
2312
2312
2313
-
**💡 Explanation:**
2314
-
If `join()` is a method on a string then it can operate on any iterable (list, tuple, iterators). If it were a method on a list, it'd have to be implemented separately by every type. Also, it doesn't make much sense to put a string-specific method on a generic `list` object API.
* Few weird looking but semantically correct statements:
2317
-
+ `[] = ()` is a semantically correct statement (unpacking an empty `tuple` into an empty `list`)
2318
-
+ `'a'[0][0][0][0][0]` is also a semantically correct statement as strings are [sequences](https://docs.python.org/3/glossary.html#term-sequence)(iterables supporting element access using integer indices) in Python.
2319
-
+ `3 --0-- 5 == 8` and `--5 == 5` are both semantically correct statements and evaluate to `True`.
* Given that `a` is a number, `++a` and `--a` are both valid Python statements but don't behave the same way as compared with similar statements in languages like C, C++ or Java.
+ There is no `++` operator in Python grammar. It is actually two `+` operators.
2334
-
+ `++a` parses as `+(+a)` which translates to `a`. Similarly, the output of the statement `--a` can be justified.
2335
-
+ This StackOverflow [thread](https://stackoverflow.com/questions/3654830/why-are-there-no-and-operators-in-python) discusses the rationale behind the absence of increment and decrement operators in Python.
* Python uses 2 bytes for local variable storage in functions. In theory, this means that only 65536 variables can be defined in a function. However, python has a handy solution built in that can be used to store more than 2^16 variable names. The following code demonstrates what happens in the stack when more than 65536 local variables are defined (Warning: This code prints around 2^18 lines of text, so be prepared!):
* Multiple Python threads won't run your *Python code* concurrently (yes you heard it right!). It may seem intuitive to spawn several threads and let them execute your Python code concurrently, but, because of the [Global Interpreter Lock](https://wiki.python.org/moin/GlobalInterpreterLock) in Python, all you're doing is making your threads execute on the same core turn by turn. Python threads are good for IO-bound tasks, but to achieve actual parallelization in Python for CPU-bound tasks, you might want to use the Python [multiprocessing](https://docs.python.org/2/library/multiprocessing.html) module.
* List slicing with out of the bounds indices throws no errors
2352
+
* 列表切片超出索引边界而不引发任何错误
2353
2353
```py
2354
2354
>>> some_list = [1, 2, 3, 4, 5]
2355
2355
>>> some_list[111:]
2356
2356
[]
2357
2357
```
2358
2358
2359
-
* `int('١٢٣٤٥٦٧٨٩')` returns `123456789` in Python 3. In Python, Decimal characters include digit characters, and all characters that can be used to form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO. Here's an [interesting story](http://chris.improbable.org/2014/8/25/adventures-in-unicode-digits/) related to this behavior of Python.
0 commit comments