Some info on that specific example: If you just want to iterate, map or filter the result, you can use a generator to avoid an array copy:
import itertools
files = itertools.islice(files, batch_size)
As for the general case: Whether you assign the new value to an already existing name or to a new name should make absolutely no difference (at least from the point of view of the interpreter/VM). Both methods produce almost the exact same bytecode:
Python 2.7.2 (default, Nov 21 2011, 17:25:27)
[GCC 4.6.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dis
>>> def func1(files):
... files = files[:100]
...
>>> def func2(files):
... new_files = files[:100]
...
>>> dis.dis(func1)
2 0 LOAD_FAST 0 (files)
3 LOAD_CONST 1 (100)
6 SLICE+2
7 STORE_FAST 0 (files)
10 LOAD_CONST 0 (None)
13 RETURN_VALUE
>>> dis.dis(func2)
2 0 LOAD_FAST 0 (files)
3 LOAD_CONST 1 (100)
6 SLICE+2
7 STORE_FAST 1 (new_files)
10 LOAD_CONST 0 (None)
13 RETURN_VALUE
The same can be observed in Python 3.
In fact, func1
could even be a bit faster, because the name files
has been seen before and could already be in some variable lookup cache.