Default kwarg values for Python's str.format() method
问题 I'm looking to try and keep pluralisation of existing strings as simple as possible, and was wondering if it was possible to get str.format() to interpret a default value when looking for kwargs. Here's an example: string = "{number_of_sheep} sheep {has} run away" dict_compiled_somewhere_else = {'number_of_sheep' : 4, 'has' : 'have'} string.format(**dict_compiled_somewhere_else) # gives "4 sheep have run away" other_dict = {'number_of_sheep' : 1} string.format(**other_dict) # gives a key