我正在使用python生成LaTeX代码(长话大说-我需要进行120多次独特的考试)。
This means that I have lots of strings that have \
or {
or }
etc. So I'm making them literals. However, I also want to have Python calculate numbers and put them in. So I might have a string like:
r"What is the domain of the function $\exp{-1/(VARIABLE - x^2+y^2)}$?"
which I want to write to a file. But I want VARIABLE
to be a random numerical value. The question isn't how to calculate VARIABLE, but rather is there a clean way to put VARIABLE into the string, without something like:
r"What is the domain of the function $\exp{-1/(" + str(VARIABLE) + r"- x^2+y^2)}$?"
我将做很多事情,因此,如果可行,那就太好了。我有Python 3.5.2。