Return a tuple of arguments to be fed to string.format()

前端 未结 3 473
清酒与你
清酒与你 2020-12-13 18:10

Currently, I\'m trying to get a method in Python to return a list of zero, one, or two strings to plug into a string formatter, and then pass them to the string method. My c

3条回答
  •  自闭症患者
    2020-12-13 18:48

    Format is preferred over the % operator, as of its introduction in Python 2.6: http://docs.python.org/2/library/stdtypes.html#str.format

    It's also a lot simpler just to unpack the tuple with * -- or a dict with ** -- rather than modify the format string.

提交回复
热议问题