This line of code stores all parameters, which require gradients and will thus be trained, into a list.
This list is then passed to the optimizer. You could also pass all parameters to the optimizer and let the check internally, if valid gradients were calculated for each parameter or if this parameter should be skipped.
The posted code snippet is a good way to write explicit code in my opinion.