python - What is difference between str.format_map(mapping) and str.format -
i don't understand str.format_map(mapping) method. know similar str.format(*args, **kwargs) method , can pass dictionary argument (please see example). example:
print ("test: argument1={arg1} , argument2={arg2}".format_map({'arg1':"hello",'arg2':123})) can explain me difference between str.format_map(mapping) , str.format(*args, **kwargs) methods , why need str.format_map(mapping) method?
str.format(**kwargs) makes new dictionary in process of calling. str.format_map(kwargs) not. in addition being faster, str.format_map() allows use dict subclass (or other object implements mapping) special behavior, such gracefully handling missing keys. special behavior lost otherwise when items copied new dictionary.
see: https://docs.python.org/3/library/stdtypes.html#str.format_map
Comments
Post a Comment