partial string formatting

前端 未结 21 1092
野的像风
野的像风 2020-11-28 04:30

Is it possible to do partial string formatting with the advanced string formatting methods, similar to the string template safe_substitute() function?

F

21条回答
  •  情话喂你
    2020-11-28 04:56

    You could wrap it in a function that takes default arguments:

    def print_foo_bar(foo='', bar=''):
        s = '{foo} {bar}'
        return s.format(foo=foo, bar=bar)
    
    print_foo_bar(bar='BAR') # ' BAR'
    

提交回复
热议问题