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
Python, being a beautifully designed high-level and interpreter-based programming language, provides us with many features for the programmer's comfort. But sometimes, the outcomes of a Python snippet may not seem obvious at first sight.
8
8
9
-
Here is a fun project attempting to explain what exactly is happening under the hood for some counter-intuitive snippets and lesser-known features in Python.
9
+
Here's a fun project attempting to explain what exactly is happening under the hood for some counter-intuitive snippets and lesser-known features in Python.
10
10
11
11
While some of the examples you see below may not be WTFs in the truest sense, but they'll reveal some of the interesting parts of Python that you might be unaware of. I find it a nice way to learn the internals of a programming language, and I believe that you'll find it interesting too!
12
12
@@ -3137,6 +3137,7 @@ The built-in `ord()` function returns a character's Unicode [code point](https:/
3137
3137
<!-- Example ID: edafe923-0c20-4315-b6e1-0c31abfc38f5 --->
3138
3138
3139
3139
```py
3140
+
# `pip install nump` first.
3140
3141
import numpy as np
3141
3142
3142
3143
def energy_send(x):
@@ -3384,7 +3385,7 @@ Let's increase the number of iterations by a factor of 10.
3384
3385
46
3385
3386
```
3386
3387
3387
-
**💡 Explanation:** The `@` operator was added in Python 3.5 keeping sthe cientific community in mind. Any object can overload `__matmul__` magic method to define behavior for this operator.
3388
+
**💡 Explanation:** The `@` operator was added in Python 3.5 keeping sthe cientific community in mind. Any object can overload `__matmul__` magic method to define behavior for this operator.
3388
3389
3389
3390
* From Python 3.8 onwards you can use a typical f-string syntax like `f'{some_var=}` for quick debugging. Example,
3390
3391
```py
@@ -3397,15 +3398,15 @@ Let's increase the number of iterations by a factor of 10.
3397
3398
3398
3399
```py
3399
3400
import dis
3400
-
exec("""
3401
-
def f():
3402
-
""" + """
3403
-
""".join(["X" + str(x) + "=" + str(x) for x in range(65539)]))
3404
-
3405
-
f()
3406
-
3407
-
print(dis.dis(f))
3408
-
```
3401
+
exec("""
3402
+
def f():
3403
+
""" + """
3404
+
""".join(["X" + str(x) + "=" + str(x) for x in range(65539)]))
3405
+
3406
+
f()
3407
+
3408
+
print(dis.dis(f))
3409
+
```
3409
3410
3410
3411
* 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.
3411
3412
@@ -3468,7 +3469,7 @@ f()
3468
3469
3469
3470
# Contributing
3470
3471
3471
-
A few ways that you can contribute to wtfpython,
3472
+
A few ways in which you can contribute to wtfpython,
3472
3473
3473
3474
- Suggesting new examples
3474
3475
- Helping with translation (See [issues labeled translation](https://github.com/satwikkansal/wtfpython/issues?q=is%3Aissue+is%3Aopen+label%3Atranslation))
0 commit comments