带splat运算符的Python字符串插值?
我有一个大的(~10个元素)整数列表,我希望将其插入到字符串中。这似乎是splat操作符的理想用例,因此我希望能够执行以下操作:带splat运算符的Python字符串插值?,python,string-interpolation,splat,Python,String Interpolation,Splat,我有一个大的(~10个元素)整数列表,我希望将其插入到字符串中。这似乎是splat操作符的理想用例,因此我希望能够执行以下操作: """[latex]$\begin{bmatrix} %d & %d \\ %d & %d\end{bmatrix} \times \begin{bmatrix} %d & %d \\ %d & %d \end{bmatrix} $[/latex]""" % (*lst) ^^
"""[latex]$\begin{bmatrix}
%d & %d \\ %d & %d\end{bmatrix}
\times
\begin{bmatrix}
%d & %d \\ %d & %d
\end{bmatrix} $[/latex]""" % (*lst)
^^^^ SyntaxError: invalid syntax
什么是一种干净的、语法上有效的方法来实现这一点?
str.\uuuumod\uuuuu
需要一个元组
'''...''' % tuple(lst)
str.\uuuu mod\uuuuu
接受一个元组
'''...''' % tuple(lst)
Ignacio给出了正确的答案,但需要注意的是,这也是Python中对*splat运算符的无效使用。Ignacio给出了正确的答案,但需要注意的是,这也是Python中对*splat运算符的无效使用。