learn kro favicon img

How to Print in Python with Examples

How to Print in Python with Examples

In Python, you can use the “print” function to output text or other values to the screen or a file. The syntax for the “print” function is as follows:

Here is a breakdown of the arguments:

  • value(s): This is the value or values that you want to print. You can pass one or more values separated by commas.
  • sep: This is the separator that is used between the values. The default value is a single space.
  • end: This is the string that is printed after all the values. The default value is a newline character.
  • file: This is the file object where you want to print the output. The default value is the standard output (i.e. the screen).
  • flush: This is a boolean value that determines whether the output is flushed (i.e. written to the file) immediately after each print statement. The default value is False.

Here are some examples of using the “print” function:

In Python 3, the “print” function is a function, not a statement, so you need to use parentheses around the values that you want to print. In Python 2, the “print” statement is used instead of the “print” function, and you don’t need to use parentheses.

Leave a Comment

Your email address will not be published. Required fields are marked *