|
|
|
|
|
by UncleEntity
2644 days ago
|
|
> so with your example above if you wrote thedictionary.get(b) rather than thedictionary.get(a) you'd get an error rather than None Technically, dict.get() returns None if the item isn't found and you don't provide a different value for its default. thedictionary[b] would throw a KeyError on the other hand. One could always subclass dict if they wanted to ensure the keys were always integers or whatever. > I've often seen learners have trouble with this sort of thing (you read a number from a file, neglect to call int(), and get mysterious lookup failures). Not sure if you're arguing for a stronger type system or having the language promote the string to an int as (I've heard) other scripting languages do. Though, once you figure out the language doesn't automagically parse files for you you're well on the way to finding more fun and exciting ways to get python to throw error messages at you. |
|