In this case, I would say: "Explicit is better than implicit."
When someone reads your code, they can make a few assumptions. They may suggest that the "words" can be either empty or with data in it (there is no case when it is None). In this case, they may be tempted to optimize your code. They may even be right to do this, unless indicated otherwise, that you can get the value None.
If the “words” can actually be “No,” I will try to clarify this:
self.words = words if words is None: self.words = {}
Or perhaps an “else” first instead of an unconditional assignment. In any case, in this way, you have a document confirming that None is the expected value for "words".
Mattias nilsson
source share