Why is there a zero argument when iterating through dataloaders (e.g. enumerate(self.trainloader, 0) )?

I’ve seen:

       for epoch in range(nb_epochs):
            for i, data in enumerate(trainloader, 0):
                # unpack data
                inputs, labels = data

but I’ve never understood why the enumerate function needs the 0 as an argument. Does anyone know why?

You can check the python doc for the specification of the enumerate() function: https://docs.python.org/3/library/functions.html#enumerate

1 Like