Question 10/13 fast.ai v3 lecture 9
We have an object called something
. If the object has an attribute val
, we would like to access it. If it doesn't, we would like to return a default value of False
.
How do we achieve this?
Answer
getattr(something, 'val', False)
Screenshot