Quantcast
Channel: I know of f-strings, but what are r-strings? Are there others? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

I know of f-strings, but what are r-strings? Are there others?

$
0
0

I started learning python for the first time in an accelerated course on data science a few weeks ago and we were introduced early on to f-strings.

The simple code:

name = 'Tim'print(f'There are some who call me {name}...')

outputs the string "There are some who call me Tim..."

Through my browsing of various packages out of curiosity, I came upon pages like this one detailing a function you can call in matplotlib to render $\LaTeX$-like expressions within the generated images. In the example code they use something similar to f-strings but with an r instead of an f.

import matplotlib.pyplot as pltplt.title(r'$\alpha > \beta$')plt.show()

The resulting (otherwise empty) graph has a title using text which has been formatted similarly to how one would expect using MathJax or $\LaTeX$ with a greek character alpha and a greek character beta.


My questions are the following:

What precisely is an r-string and how does it compare to an f-string? Are r-strings specifically used for matplotlib's mathtext and usetex?

Apart from f-strings and r-strings, are there any other notable similar string variants or alternates that I should familiarize myself with or be made aware of?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images