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""")
Output:
baransel.dev Python Lessons
baransel.dev Python Lessons
baransel.dev Python Lessons
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.')
Output:
File "/Users/baran/Downloads/test.py", line 1
print('Baransel's class ended early today.')
^
SyntaxError: invalid syntax
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.")
print("""Baransel's class ended early today.""")
Parameters of the print()
Function:
Continue this post on my blog! Python print function.
Top comments (0)