Skip to content

Commit 8b2a617

Browse files
committed
Add new snippet: Half quoted triple strings
Closes satwikkansal#40
1 parent ea29aa0 commit 8b2a617

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,26 @@ a, b = a[b] = {}, 5
17741774
print(dis.dis(f))
17751775
```
17761776
1777+
* Half triple-quoted strings (suggested by @asottile in [this](https://github.com/satwikkansal/wtfpython/issues/40) issue).
1778+
```py
1779+
>>> print('wtfpython''')
1780+
wtfpython
1781+
>>> print("wtfpython""")
1782+
wtfpython
1783+
>>> # The following statements raise `SyntaxError`
1784+
>>> # print('''wtfpython')
1785+
>>> # print("""wtfpython")
1786+
```
1787+
**💡 Explanation:**
1788+
+ Python support implicit [string literal concatenation](https://docs.python.org/2/reference/lexical_analysis.html#string-literal-concatenation), Example,
1789+
```
1790+
>>> print("wtf" "python")
1791+
wtfpython
1792+
>>> print("wtf" "") # or "wtf"""
1793+
wtf
1794+
```
1795+
+ `'''` and `"""` are also string delimiters in Python which causes a SyntaxError because the Python interpreter was expecting a terminating triple quote as delimiter while scanning the currently encountered triple quoted string literal.
1796+
17771797
* 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.
17781798
17791799
* List slicing with out of the bounds indices throws no errors

0 commit comments

Comments
 (0)