6.2 Strings

Strings can be enclosed either in single () or double (") quotes. Strings may also be enclosed by three quote characters in a row: either ’’’ or """. Special care needs to be taken when using apostrophes or quotes in single-quote delimited strings, as these characters may be misinterpreted as string delimiters, as in the example:


’Robert’s data’

This easiest way to avoid such problems is to use three quotes:


’’’Robert’s data’’’

Special characters such as tabs and newlines can be inserted into strings using escape codes such as $\backslash $t and $\backslash $n; see Table 6.1 for a list of these. The following string is split over three lines:

pyxplot> print e’the moon,$\backslash $nthe moon,$\backslash $nThey danced by the light of the moon.’
the moon,
the moon,
They danced by the light of the moon.

Sometimes these escape codes can be rather annoying, especially when entering latex control codes, which all begin with backslash characters. Rather than having to escape every backslash, it is generally easier to prefix the string with the character r, which turns off all escape codes:

pyxplot> print r”’I escaped the quote by typing $\backslash $’.”’
I escaped the quote by typing $\backslash $’.

Escape sequence


$\backslash $?

Question mark

$\backslash $


$\backslash $"

Double quote

$\backslash \backslash $

Literal backslash

$\backslash $a

Bell character

$\backslash $b


$\backslash $f


$\backslash $n


$\backslash $r

Carriage return

$\backslash $t

Horizontal tab

$\backslash $v

Vertical tab

Table 6.1: A complete list of Pyxplot’s string escape sequences. These are a subset of those available in C.

Once defined, a string variable can be used anywhere in Pyxplot where a quoted string could have been used, for example in the set title command:

plotname = "Insert title here"
set title plotname

Strings can be concatenated together using the + operator:

pyxplot> print "pi = " + pi.str()
pi = 3.1415927