Navigation

  • index
  • next |
  • previous |
  • Hands-on Python Tutorial »
  • 1. Beginning With Python »

1.7. Print Function, Part IΒΆ

In interactive use of the Python interpreter, you can type an expression and immediately see the result of its evaluation. This is fine to test out syntax and maybe do simple calculator calculations. In a program run from a file like the first sample program, Python does not display expressions this way. If you want your program to display something, you can give explicit instructions with the print function. Try in the Shell:

x = 3
y = 5
print('The sum of', x, 'plus', y, 'is', x+y)

The print function will prints as strings everything in a comma-separated sequence of expressions, and it will separate the results with single blanks, and advance to the next line at the end, by default. Note that you can mix types: anything that is not already a string is automatically converted to its string representation.

You can also use it with no parameters:

print()

to only advance to the next line.

Previous topic

1.6. Variables and Assignment

Next topic

1.8. Strings Part II

This Page

  • Show Source

Quick search

Enter search terms or a module, class or function name.

Navigation

  • index
  • next |
  • previous |
  • Hands-on Python Tutorial »
  • 1. Beginning With Python »
© Copyright 2019, Dr. Andrew N. Harrington. Last updated on Jan 05, 2020. Created using Sphinx 1.3.1+.