Why is a single β€œfor” expression expressed faster in Python?

I checked four situations.

1.

testList = list() for i in range(1000000): testList.append(i) 

2.

 testList = list() for i in range(1000000): testList.append(i) 

3.

 testList = list() newAppend = testList.append for i in range(1000000): newAppend(i) 

4.

 [i for i in range(1000000)] 

Everytime

1: 0.09166

2: 0.08299

3: 0,05003

4: 0.04594

Why are others faster than 1?

Can I find related keywords?

+5
source share

Source: https://habr.com/ru/post/1270210/


All Articles