Python provides a print function that displays the value of a variable. For example,
print
>>> freq = 22.0/7.0 >>> x = 7.234 >>> print('Vibration frequency = ', freq) Vibration frequency = 3.14285714286 >>> print('Vibration frequency = ', freq, 'Displacement =\ ... ', x) Vibration frequency = 3.14285714286 Displacement = 7.234
%
%s
>>> print('Vibration frequency = %s Displacement =\ ... %s' % (freq, x)) Vibration frequency = 3.14285714286 Displacement = 7.234
%f
>>> print('Vibration frequency = %6.2f Displacement =\ ... %6.2f' % (freq, x)) Vibration frequency = 3.14 Displacement = 7.23
%E
>>> print('Vibration frequency = %.6E Displacement =\ ... %.2E' % (freq, x)) Vibration frequency = 3.142857E+00 Displacement = 7.23E+00
The + flag indicates that a number should include a sign.
+
The \n escape sequence inserts a new line.
\n
The \t escape sequence inserts a tab character.
\t
For example,
>>> print('Vibration frequency = %+.6E\nDisplacement =\ ... %+.2E' % (freq, x)) Vibration frequency = +3.142857E+00 Displacement = +7.23E+00