Ask HN: What's your favorite Python quirk? 3 points by wampler 10y ago ↗ HN Any unusual or unexpected feature of the language
[–] jordigh 10y ago ↗ There's a nice list here:https://github.com/cosmologicon/pywatHere's another one. Compare "x = 256; y = 256; x is y" with "x = 257" (enter) "y = 257" (enter) "x is y" with "x = 257; y = 257; x is y". It makes a difference whether x and y are assigned on the same line or not. From here:http://glasnt.com/blog/2016/05/28/on-language-oddities.html [–] wampler 10y ago ↗ Thanks for sharing!
[–] wampler 10y ago ↗ Abusing locals() - learnt it from @jrollerdef foo(): """ >>> foo() {'a': 1, 'c': 3, 'b': 2} """ a = 1 b = 2 c = 3 return locals()
[–] probinso 10y ago ↗ My favorite quirk was deprecated.Python 2.xdef function(a, (b, c)): # pattern extract matches a strictly two-elementsPython 3.xdef function(a, b_c): # not as clean, nor as expressive
4 comments
[ 1.8 ms ] story [ 23.6 ms ] threadhttps://github.com/cosmologicon/pywat
Here's another one. Compare "x = 256; y = 256; x is y" with "x = 257" (enter) "y = 257" (enter) "x is y" with "x = 257; y = 257; x is y". It makes a difference whether x and y are assigned on the same line or not. From here:
http://glasnt.com/blog/2016/05/28/on-language-oddities.html
def foo(): """ >>> foo() {'a': 1, 'c': 3, 'b': 2} """ a = 1 b = 2 c = 3 return locals()
Python 2.x
def function(a, (b, c)): # pattern extract matches a strictly two-elements
Python 3.x
def function(a, b_c): # not as clean, nor as expressive