Skip to content

Instantly share code, notes, and snippets.

@dvl
Last active August 29, 2015 14:23
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 dvl/c6862761b99f0ef265c1 to your computer and use it in GitHub Desktop.
Save dvl/c6862761b99f0ef265c1 to your computer and use it in GitHub Desktop.
$ python test.py
4 0 LOAD_CONST 3 ('aaaaaaaaaaaaaaaaaaaa')
3 STORE_FAST 0 (a)
5 6 LOAD_CONST 4 ('aaaaaaaaaaaaaaaaaaaa')
9 STORE_FAST 1 (b)
7 12 LOAD_FAST 0 (a)
15 LOAD_FAST 1 (b)
18 COMPARE_OP 8 (is)
21 RETURN_VALUE
********************************************************************************
10 0 LOAD_CONST 1 ('a')
3 LOAD_CONST 2 (21)
6 BINARY_MULTIPLY
7 STORE_FAST 0 (a)
11 10 LOAD_CONST 1 ('a')
13 LOAD_CONST 2 (21)
16 BINARY_MULTIPLY
17 STORE_FAST 1 (b)
13 20 LOAD_FAST 0 (a)
23 LOAD_FAST 1 (b)
26 COMPARE_OP 8 (is)
29 RETURN_VALUE
from dis import dis
def test1():
a = 'a' * 20
b = 'a' * 20
return a is b
def test2():
a = 'a' * 21
b = 'a' * 21
return a is b
if __name__ == '__main__':
dis(test1)
dis(test2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment