Coming from Swift I'm having a bit of a hard time working with .None type of Python. I have a few functions which might return None
if the object I'm looking for is not found in the array.
Then I have to nest my code as follows:
varA = self.getVariableByName(Variables.varA)
if varA is None:
varB = self.getVariableByName(Variables.varB)
varC = self.getVariableByName(Variables.varC)
if varB is not None and varC is not None:
# Do something with varB and varC
In Swift I used to be able to bind the variables in the if statement
let f = getVariableByName
if f(Variables.varA) == nil, let varB = f(Variables.varB), let varC = f(Variables.varC) {
// Do something with varB and varC
}
What is a more 'pythonic' way of dealing with None
?