Jan-05-2018, 07:55 PM
Wolfpack2605 Wrote:I have no clue what val is or what .get is. Please explain.val is merely the variable name the example chose to use here.
.get is a method provided by dictionaries
your example Wrote:dictionaries provide the get method to do this:
val = d.get(key, 'default')
python documentation Wrote:dict.get = get(...)So calling d.get(key, 'default') returns the value of the key (if the key exists in the dictionary), or 'default' (if the key does not exist). After running your example which I quoted, val will contain what is returned.
D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.