Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does r in smp.symbols(r'\theta_1 \theta_2', cls=smp.Function) mean?

I am new to sympy, and I am following a guide to using it for physics.

There’s a line which says:
smp.symbols(r'\theta_1 \theta_2', cls=smp.Function)

What does the r before the '\theta_1 \theta_2' means? I have not been able to find anything…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So far, I have noticed that removing it

Screenshot without the r, using jupyter

kind of messes with the variable name, given that it has a \ for "LaTeX".

Thanks for any insights you may provide!!

>Solution :

r"xxx" indicates a "raw string", in which backslash escapes are not processed. The string "\theta" by itself contains 5 characters: a tab, and the letters "heta". But the string r"\theta" contains 6 characters: a backslash, a ‘t’, and then ‘heta’.

You can also write "\\theta_1 \\theta_2", but raw strings save you from having to double the backslashes.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading