Repository navigation
exercise5/answer.py: .get() with a default and .get() without — why both forms?
#31
Replies: 1 comment
|
Yes — the contrast is the point of exercise 5, and the trailing period is a deliberate key-exactness demo. Breaking down print(weirdo_1.get("fast", "sluggish")) # None? no — "sluggish"
...
print(michael.get("car")) # None, no errorThe two forms teach different halves of
The contrast that makes this land is with square brackets: The trailing period in |
Uh oh!
There was an error while loading. Please reload this page.
answers/exercise5/answer.pyuses both forms:The first supplies a fallback (
"sluggish"), the second returnsNonefor the missing"car"key. Was the contrast deliberate — demonstrating that.get()has an optional default — and is there a reason the"michael."key includes a trailing period?All reactions