Printing in Python is as simple as typing print followed by the string you wish to print. You do not need to import any libraries.
1 2 |
>>> print "Hello World" Hello World |
You can also print the value of an integer or list simply by print
1 2 3 4 5 6 |
>>> x = [1, 2, 3] >>> print x [1, 2, 3] >>> y = 2 >>> print y 2 |
If, however, you want to print a string AND some integer (or list), you need to cast to string.
1 2 3 |
>>> x = 42 >>> print "The meaning of life is " + str(x) The meaning of life is 42 |
Some notes about print:
- It will automatically enter a new-line character at the end of the string.
- Casting to string is only necessary when there is more than one type on the print line.
- Additional information on how print works: http://docs.python.org/reference/simple_stmts.html#print




