3 ms·
The default value (the second argument of the `get` method) defaults to `None` anyways. Therefore, D.get(key, None) is just syntax noise (in the best case -
by tomp 12y ago
The default value (the second argument of the `get` method) defaults to `None` anyways. Therefore,
D.get(key, None)
is just syntax noise (in the best case - in the worst case, it signifies someone who doesn't know/understand Python).
D.get(key)
should be used instead, or
D.get(key, "whatever")
if required.
- bpeebles 12y agoOf course, sometimes I still type: D.get(key, None) since I forget that dict.get and getattr() have different behavior in the case of missing keys/attributes...