set default method in python code example
Example 1: set default python
newDict = {1:"One",
2:"Two",
3:"Three"}
x=newDict.setdefault(4,"Four")
print(newDict[4])
newDict2 = {1:"One",
2:"Two",
3:"Three",
"Hello":"World"}
y=newDict.setdefault("Hello","Yellow")
print(newDict2["Hello"])
dict1 = {1:"One",2:"Two"}
x=dict1.setdefault(3,"Three")
x=dict1.setdefault(2,"Duo")
print(dict1)
Example 2: python default value
d = {'a': 1, 'b': 2}
print(d.get('c', 3))
Example 3: python default function value
def munge(sep: AnyStr = None): ...
def munge(input: AnyStr, sep: AnyStr = None, limit=1000): ...