Simple Output

Numbers

Numbers are easy in python:
Integers
10, -4, 0
Reals
10.5, -30.3, 0.0
Imaginary
5j, -3J, (3+3j)
All the normal mathematical operators apply.

Strings

Python has several types of literal strings, use which ever is the most convenient:
Single quoted
'Single quoted strings must quote any \'s in them,
	  but "s don't have to be.'
Double quoted
"Double quoted strings must quote any \"s in them,
	  but 's don't have to be"
Triple quoted
"""Triple quoted strings are
   used when you want the
   string to span more than 
   one line."""
	

Some Examples

Strings

Python normally puts newlines at the end of a print statement:
print "foo"
print "bar"
      
outputs:
foo
bar
      
while
print "foo",
print "bar"
      
outputs:
foo bar
      
Note the space between foo and bar, this makes it easy to print out a lot of variables:
a="a"
b="b"
c="c"
print a,b,c
      
outputs:
a b c
      
but it can be a pain at times. A useful operator on strings is the multiplier:
print '-' * 30
    
outputs:
------------------------------
    

Numbers

Python's print function supports a scanf type usage:
print "The value of pi is approximately %5.3f." % 3.14159265359
    
outputs:
The value of pi is approximately 3.142.
    

Prev Contents Next
Clinton Roy