Python Print() Statement: How to Print with Examples

โšก Smart Summary

Python print() function displays a message or object on the screen after converting it to a string. The examples below show how to print strings, blank lines, and multiple items, and how to control line endings.

  • ๐Ÿ–จ๏ธ Purpose: The print() function outputs strings and objects to the screen.
  • ๐Ÿ”ค Syntax: Call print(object(s)) with the value you want to display.
  • ๐Ÿ” Multiple Prints: Each print() call outputs on its own new line by default.
  • โฌœ Blank Lines: Use “\n” or multiply it to print empty lines.
  • โžก๏ธ end Parameter: Change the line ending, for example end=’ ‘, in Python 3.
  • โš ๏ธ Version Note: Python 3 uses print() as a function; Python 2 used it as a statement.

Python Print() Statement

Python print() function

The print() function in Python is used to print a specified message on the screen. The print command in Python prints strings or objects which are converted to a string while printing on a screen.

Syntax:

print(object(s))

How to Print a simple String in Python?

More often then not you require to Print strings in your coding construct.

Here is how to print statement in Python 3:

Example: 1

To print the Welcome to Guru99, use the Python print statement as follows:

print ("Welcome to Guru99")

Output:

Welcome to Guru99

In Python 2, same example will look like

print "Welcome to Guru99"

Example 2:

If you want to print the name of five countries, you can write:

print("USA")
print("Canada")
print("Germany")
print("France")
print("Japan")

Output:

USA
Canada
Germany
France
Japan

How to print blank lines

Sometimes you need to print one blank line in your Python program. Following is an example to perform this task using Python print format.

Example:

Let us print 8 blank lines. You can type:

print (8 * "\n")

or:

print ("\n\n\n\n\n\n\n\n\n")

Here is the code

print ("Welcome to Guru99")
print (8 * "\n")
print ("Welcome to Guru99")

Output

Welcome to Guru99







Welcome to Guru99

Print end command

By default, the print function in Python ends with a newline. This function comes with a parameter called ‘end’. The default value of this parameter is ‘\n’, i.e., the new line character. You can end a print statement with any character or string using this parameter. This is available only in Python 3+.

Example 1:

print("Welcome to", end=' ')
print("Guru99", end='!')

Output:

Welcome to Guru99!

Example 2:

# ends the output with '@'
print("Python", end='@')

Output:

Python@

FAQs

In Python 2, print was a statement written as print “text”. In Python 3, print is a function called as print(“text”) with parentheses. Python 3 is the current standard, so always use the function form.

The sep parameter sets the separator placed between multiple items in one print() call. By default it is a space. For example, print(“a”, “b”, sep=”-“) outputs a-b instead of a b.

Use an f-string, such as print(f”Hello {name}”), or separate items with commas, such as print(“Hello”, name). F-strings are the modern, readable way to mix text and variables in Python 3.6 and later.

Yes. AI assistants can spot missing parentheses, wrong quotes, or Python 2 syntax, and explain the exact error. They also suggest cleaner ways to format output, which helps beginners fix print-related mistakes quickly.

print() is a simple way to inspect data, model outputs, and intermediate values while building AI programs. Developers use it to trace how data flows through code, though logging libraries are preferred for larger projects.

Summarize this post with: