wtfpython
wtfpython copied to clipboard
What the f*ck Python? 😱
* when one grapheme becomes two unicodepoints, thus len(string) is two: ```py len('g̈') 'U+', hex(ord('g̈'[0])) #returns the first ``` * despite added support for ordered dicts, the order does not...
I definitely think this repo should include an example about how messed up relative imports are in Python, just read this thread https://stackoverflow.com/questions/16981921/relative-imports-in-python-3 `file structure` ``` main.py mypackage/ __init__.py module1.py...
Surprisingly, Python allows you to change the `__class__` attribute of an object: ``` In [1]: class A: ...: def __init__(self): ...: self.x = 5 ...: self.y = "hi" ...: ...:...
Original code: ```python x = 5 class SomeClass: x = 17 y = [x for i in range(10)] ``` I find the expression in `in` is bind to x in...
Python 2 is no longer supported. There is no sense to maintain something deprecated. I recommend to remove all Python 2 examples from the tutorial. This will make the tutorial...
You suggest to read the examples chronologically, but how can I do that? I don't see any dates attached to them, and the asterisks show that you insert new ones...
Utter madness. ```python >>> r = 1 >>> r 1 >>> 𝕣 = 2 >>> 𝕣 2 >>> r 2 ``` I'm not sure why this is happening – not...
Most languages do not allow an else statement without an if. However, python allows the else statement to be executed without the if provided the loop before it has not...
Definitely not a Python-related wtf, but nice to know anyways ```py >>> round(1.25, 1) 1.2 >>> round(1.35, 1) 1.4 ``` ```py >>> round(1.45) + round(1.55) == 3 True ``` https://docs.python.org/3/tutorial/floatingpoint.html#tut-fp-issues
``` >>> nan = float("nan") >>> nan == nan False >>> [nan] == [nan] True ``` Explanation: In most containers python assumes identical objects must be equal and does not...