Skip to content

Instantly share code, notes, and snippets.

@mattrobenolt
Forked from anonymous/gist:4299906
Created December 15, 2012 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrobenolt/4299924 to your computer and use it in GitHub Desktop.
Save mattrobenolt/4299924 to your computer and use it in GitHub Desktop.
>>> f1 = lambda i: '%s' % i
>>> f2 = lambda i: '%s'.format(i)
>>> import dis
>>> dis.dis(f1)
1 0 LOAD_CONST 1 ('%s')
3 LOAD_FAST 0 (i)
6 BINARY_MODULO
7 RETURN_VALUE
>>> dis.dis(f2)
1 0 LOAD_CONST 1 ('%s')
3 LOAD_ATTR 0 (format)
6 LOAD_FAST 0 (i)
9 CALL_FUNCTION 1
12 RETURN_VALUE
>>> f3 = lambda i: `i`
>>> dis.dis(f3)
1 0 LOAD_FAST 0 (i)
3 UNARY_CONVERT
4 RETURN_VALUE
>>> f4 = lambda i: str(i)
>>> dis.dis(f1)
1 0 LOAD_GLOBAL 0 (str)
3 LOAD_FAST 0 (i)
6 CALL_FUNCTION 1
9 RETURN_VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment