Skip to content

Instantly share code, notes, and snippets.

@avalanchy
Created May 22, 2014 12:53
Show Gist options
  • Select an option

  • Save avalanchy/09b260ea6f6cf68e8856 to your computer and use it in GitHub Desktop.

Select an option

Save avalanchy/09b260ea6f6cf68e8856 to your computer and use it in GitHub Desktop.
Python bool casting
>>> from dis import dis
>>> a = lambda: bool('')
>>> b = lambda: not not ''
>>> dis(a)
1 0 LOAD_GLOBAL 0 (bool)
3 LOAD_CONST 1 ('')
6 CALL_FUNCTION 1
9 RETURN_VALUE
>>> dis(b)
1 0 LOAD_CONST 1 ('')
3 UNARY_NOT
4 UNARY_NOT
5 RETURN_VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment