-
-
Save IndhumathyChelliah/c317d7c5df39e557f0e5c6e1e8f76ddd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
#default_factory is mentioned. | |
def func(): | |
return NotAvailable | |
d=defaultdict(func) | |
d['a']=1 | |
d['b']=2 | |
#default_factory attribute is given as user_defined function. | |
print (d)#Output:defaultdict(<function func at 0x00827808>, {'a': 1, 'b': 2}) | |
#Calling func raises NameError. | |
print (d.__missing__('a')) #Output:NameError: name 'NotAvailable' is not defined | |
print (d.__missing__('z'))#Output:NameError: name 'NotAvailable' is not defined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment