I inherited a python program (more like a large number of scripts) that I'm rewriting into an OOP program. I'm still learning Python and ran into this line of code which I am uncertain about.
Unfortunately I don't know what this operation is called so my searches have not been very successful.
bands = [int(b) for b in bands] if bands is not None else [10, 11]
I think this code looks at the 'bands' variable and if it is not 'None', loops through the variable and casts each entry in the list to int. If 'bands' is empty it sets 'bands' equal to a list containing 10 and 11.
Is my analysis of the code correct?
The code looks foreign to me though, kind of backwards. Is there a specific reason someone would want to write code this way instead of a normal if statement? Is it faster or does it have any other benefit?
Aucun commentaire:
Enregistrer un commentaire