2.3 Printing Text

PyXPlot has a print command for displaying strings and the results of calculations to the terminal, for example:

a=2
print "Hello World!"
print a
f(x) = x**2
a=3
print "The value of",a,"squared is",f(a)

Values may also be substituted into strings using the % operator, which works in a similar fashion to Python string substitution operator1. The list of values to be substituted into the string should be a ()-bracketed list2:

print "The value of %d squared is %d."%(a,f(a))
print "The %s of f(%f) is %d."%("value",sqrt(2),f(sqrt(2)))

Footnotes

  1. For a description of this, see Guido van Rossum’s Python Library Reference: http://docs.python.org/lib/typesseq-strings.html
  2. Unlike in Python, the brackets are obligatory; ’%d’%2 is not valid in PyXPlot.