Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary methods
#3
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(...)
D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
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.
Reply


Messages In This Thread
Dictionary methods - by Wolfpack2605 - Jan-04-2018, 01:12 AM
RE: Dictionary methods - by Mekire - Jan-04-2018, 01:29 AM
RE: Dictionary methods - by jajjaja - Jan-05-2018, 07:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Dictionary Methods Wolfpack2605 2 2,420 Jan-28-2018, 12:51 AM
Last Post: league55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020