6.2 StringsStrings 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:
This easiest way to avoid such problems is to use three quotes:
Special characters such as tabs and newlines can be inserted into strings using escape codes such as t and n; see Table 6.1 for a list of these. The following string is split over three lines: pyxplot> print e’the moon,nthe moon,nThey 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 ’.”’
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()
|