PyXPlot’s print command can be used to display strings and the results of calculations on the terminal, as in the following examples:
pyxplot> a=2
pyxplot> print "Hello World!"
Hello World!
pyxplot> print a
2
Multiple items can be displayed one-after-another on a single line by separating them with commas. The following example displays the values of the variable a and the function f(a) in the middle of a text string:
pyxplot> f(x) = x**2
pyxplot> a=3
pyxplot> print "The value of ",a," squared is ",f(a),"."
The value of 3 squared is 9.
A similar effect is often achieved more neatly using the string substitution operator, %. The operator is preceded by a format string, in which the places where numbers and strings are to be substituted are marked by tokens such as %e and %s. The substitution operator is followed by a ()-bracketed list of the quantities which are to be substituted into the format string. This behaviour is similar to that of the Python programming language’s % operator1, and of the printf command in C. The following examples demonstrate the use of this operator:
pyxplot> print "The value of %d squared is %d."%(a,f(a))
The value of 3 squared is 9.
pyxplot> print "The %s of f(%f) is %d."%("value",sqrt(2),
.......> f(sqrt(2)) )
The value of f(1.414214) is 2.
The detailed behaviour of the string substitution operator, and a full list of the substitution tokens which it accepts, are given in Section 6.1.1.
Footnotes