DEV Community

Cover image for Python print function
Baransel
Baransel

Posted on • Updated on

Python print function

Sign up to my newsletter!.

What is the print() Function?

To explain briefly without confusing you too much, the print() function is a function that allows us to output to the screen.

How to Use the print() Function?

The print() function has three different uses;

  • Single quotes (' ')
  • Double quotes (" ")
  • Three quotes (“”” “””)

Let's look at an example;

print('baransel.dev Python Lessons')
print("baransel.dev Python Lessons")
print("""baransel.dev Python Lessons""")
Enter fullscreen mode Exit fullscreen mode

Output:

baransel.dev Python Lessons
baransel.dev Python Lessons
baransel.dev Python Lessons
Enter fullscreen mode Exit fullscreen mode

and you will get the same result in all three uses, why are there three different ways of use?

Let me explain it to you with a few examples;

You want to get an output like this;

Baransel's class ended early today.

If you write the example like this;

print('Baransel's class ended early today.')
Enter fullscreen mode Exit fullscreen mode

Output:

  File "/Users/baran/Downloads/test.py", line 1
    print('Baransel's class ended early today.')
                    ^
SyntaxError: invalid syntax
Enter fullscreen mode Exit fullscreen mode

In other words, the reason for the syntax error is that Python starts with the first quotation mark and ends when it sees the second quotation. Since it cannot read the text after the second quotation, it gives a syntax error. For this, a usage like this would be more accurate.

print("Baransel's class ended early today.")
Enter fullscreen mode Exit fullscreen mode
print("""Baransel's class ended early today.""")
Enter fullscreen mode Exit fullscreen mode

Parameters of the print() Function:

Continue this post on my blog! Python print function.

Oldest comments (0)