In [4]:
import dis
import math
In [7]:
def func(n):
x = 0
for i in range(n):
x += i
return x
dis.dis(func)
2 0 LOAD_CONST 1 (0)
3 STORE_FAST 1 (x)
3 6 SETUP_LOOP 30 (to 39)
9 LOAD_GLOBAL 0 (range)
12 LOAD_FAST 0 (n)
15 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
18 GET_ITER
>> 19 FOR_ITER 16 (to 38)
22 STORE_FAST 2 (i)
4 25 LOAD_FAST 1 (x)
28 LOAD_FAST 2 (i)
31 INPLACE_ADD
32 STORE_FAST 1 (x)
35 JUMP_ABSOLUTE 19
>> 38 POP_BLOCK
5 >> 39 LOAD_FAST 1 (x)
42 RETURN_VALUE
Content source: mbuchove/notebook-wurk-b
Similar notebooks: