Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Python Basics2

Python Print() Statement: How to Print with Examples

Uploaded by

Sridhar M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Python Basics2

Python Print() Statement: How to Print with Examples

Uploaded by

Sridhar M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

12/13/24, 11:28 PM Python Print() Statement: How to Print with Examples

Python Print() Statement: How to Print with


Examples
By : Logan Young Updated August 12, 2024

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))

Table of Contents:

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:

This code is editable. Click Run to Execute

1 print ("Welcome to Guru99")

https://www.guru99.com/print-python-examples.html 1/8
12/13/24, 11:28 PM Python Print() Statement: How to Print with Examples

Run

Output:
Welcome to Guru99

In Python 2, same example will look like

This code is editable. Click Run to Execute

1 print "Welcome to Guru99"

Run

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

This code is editable. Click Run to Execute

https://www.guru99.com/print-python-examples.html 2/8
12/13/24, 11:28 PM Python Print() Statement: How to Print with Examples

1 print("USA")
2 print("Canada")
3 print("Germany")
4 print("France")
5 print("Japan")

Run

Output:

USA
Canada
Germany
France
Japan

RELATED ARTICLES
→ Multithreading in Python with Example: Learn GIL in Python
→ Go Vs. Python: What’s the Difference?
→ How to Remove Duplicates from a List in Python
→ Palindrome Program in Python

How to print blank lines

https://www.guru99.com/print-python-examples.html 3/8
12/13/24, 11:28 PM Python Print() Statement: How to Print with Examples

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:

This code is editable. Click Run to Execute

1 print (8 * "\n")

Run

or:

This code is editable. Click Run to Execute

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

https://www.guru99.com/print-python-examples.html 4/8
12/13/24, 11:28 PM Python Print() Statement: How to Print with Examples

Run

Here is the code


This code is editable. Click Run to Execute

1 print ("Welcome to Guru99")


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

Run

Output

Welcome to Guru99

Welcome to Guru99

Print end command


https://www.guru99.com/print-python-examples.html 5/8
12/13/24, 11:28 PM Python Print() Statement: How to Print with Examples

By default, 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 in 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@

You Might Like:

Top
Top Python PyQt5 Tutorial
Tutorial
Interview with Examples:
Examples: Multithreading in
Questions and… Design…
Design… Python with…

https://www.guru99.com/print-python-examples.html 6/8
12/13/24, 11:28 PM Python Print() Statement: How to Print with Examples

Import module in
Python
Python with
Examples
Examples

Prev Report a Bug Next

Do you think
AI is future of
Work?
Yes No

About
About Us
Advertise with Us
Contact Us

https://www.guru99.com/print-python-examples.html 7/8
12/13/24, 11:28 PM Python Print() Statement: How to Print with Examples

Career Suggestion
SAP Career Suggestion Tool
Software Testing as a Career
Xero
RemotePC
QuickBooks

Interesting
eBook
Blog
Quiz
SAP eBook
Privacy Manager

English © Copyright - Guru99 2024 Privacy Policy |


Affiliate Disclaimer | ToS | Editorial Policy

https://www.guru99.com/print-python-examples.html 8/8

You might also like