Skip to content

Instantly share code, notes, and snippets.

@alexandre
Created November 27, 2014 01:53
Show Gist options
  • Select an option

  • Save alexandre/48382e94a527402979d4 to your computer and use it in GitHub Desktop.

Select an option

Save alexandre/48382e94a527402979d4 to your computer and use it in GitHub Desktop.
not_not and if_else
>>> def not_not(x):
... return not(not x)
...
>>> def if_else(x):
... return True if x else False
...
>>> import dis
>>> dis.dis(not_not)
2 0 LOAD_FAST 0 (x)
3 UNARY_NOT
4 UNARY_NOT
5 RETURN_VALUE
>>> dis.dis(if_else)
2 0 LOAD_FAST 0 (x)
3 POP_JUMP_IF_FALSE 10
6 LOAD_CONST 1 (True)
9 RETURN_VALUE
>> 10 LOAD_CONST 2 (False)
13 RETURN_VALUE
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment