Dictionary setdefault,setdefault,#The setdefa
Dictionary setdefault,setdefault,#The setdefa
#The setdefault method is somewhat similar to get, except that in addition to the get #functionality, setdefault sets the value corresponding to the given key if it is not #already in the dictionary:d = {}print d.setdefault('name', 'N/A')print dd['name'] = 'Gumby'd.setdefault('name', 'N/A')print d#As you can see, when the key is missing, setdefault returns the default and updates #the dictionary accordingly. If the key is present, its value is returned and the #dictionary is left unchanged. The default is optional, as with get; if it is left #out, None is used:d = {}print d.setdefault('name')print d
- Return a function and call it,returnfunction,def f1():
- Finding the Direct Children of a Node,findingnode,def
- Normalizing Character Data Before Output,,import sysfr
- convert integers to octal and hexadecimal strings with a
- Link Python print stream into a file,pythonstream,impo
- Print with format: %o, %x and %X,%o%x,print '%o %x
热门文章:
相关内容
- Return a function and call it,returnfunction,def f1():
- Finding the Direct Children of a Node,findingnode,def randomCh
- Normalizing Character Data Before Output,,import sysfr
- convert integers to octal and hexadecimal strings with a string forma
- Link Python print stream into a file,pythonstream,import syspr
- Print with format: %o, %x and %X,%o%x,print '%o %x
- Assorted Tk-related subroutines used in Grail,,'''Assorted
- print accepts various data types,acceptsvarious,letter = 'c'
- Pass function as parameter 2,passparameter,def minmax(t
- Replace one,replaceone,S = 'xxxxSPA
评论关闭