Python print function

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…


This content originally appeared on DEV Community and was authored by Baransel

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.


This content originally appeared on DEV Community and was authored by Baransel


Print Share Comment Cite Upload Translate Updates
APA

Baransel | Sciencx (2022-02-08T10:14:06+00:00) Python print function. Retrieved from https://www.scien.cx/2022/02/08/python-print-function/

MLA
" » Python print function." Baransel | Sciencx - Tuesday February 8, 2022, https://www.scien.cx/2022/02/08/python-print-function/
HARVARD
Baransel | Sciencx Tuesday February 8, 2022 » Python print function., viewed ,<https://www.scien.cx/2022/02/08/python-print-function/>
VANCOUVER
Baransel | Sciencx - » Python print function. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/08/python-print-function/
CHICAGO
" » Python print function." Baransel | Sciencx - Accessed . https://www.scien.cx/2022/02/08/python-print-function/
IEEE
" » Python print function." Baransel | Sciencx [Online]. Available: https://www.scien.cx/2022/02/08/python-print-function/. [Accessed: ]
rf:citation
» Python print function | Baransel | Sciencx | https://www.scien.cx/2022/02/08/python-print-function/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.