Skip to content Skip to sidebar Skip to footer

Pass *args To String.format In Python?

Is it possible to pass *args to string.format? I have the following function: @classmethod def info(cls, component, msg, *args): '''Log an info message''' cls.__log(cls.Lev

Solution 1:

I think what you want to do is

msg.format(*args)

Solution 2:

Yes it is.

>>> a=(1,2,3,4)
>>> "{0}{1}{2}{3}".format(*a)
'1234'

Post a Comment for "Pass *args To String.format In Python?"