Skip to main content

Python Print() Statement: How to Print with Examples

 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 than 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 FutureCode, use the Python print statement as follows:

print ("Welcome to FutureCode")                                                                                       


Output:

Welcome to FutureCode

In Python 2, the same example will look like

print "Welcome to FutureCode"                                                             

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 FutureCode")
print (8 * "\n") print ("Welcome to FutureCode")

Output

Welcome to FutureCode
Welcome to FutureCode

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 ("FutureCode", end = '!')

Output:

Welcome to FutureCode!


Example 2:

# ends the output with ‘@.’

print("Python" , end = '@')

Output:

Python@

Comments

Popular posts from this blog

What to expect from AI in 2023

  As a rather commercially successful author once wrote, “the night is dark and full of terrors, the day bright and beautiful and full of hope.” It’s fitting imagery for AI, which like all tech has its upsides and downsides. Art-generating models like  Stable Diffusion , for instance, have led to incredible outpourings of creativity, powering  apps , and even  entirely new business models . On the other hand, its open-source nature lets bad actors use it to create  deepfakes  at scale — all while  artists protest that it’s profiting off of their work . What’s on deck for AI in 2023? Will regulation rein in the worst of what AI brings, or are the floodgates open? Will powerful, transformative new forms of AI emerge, a la  ChatGPT , and disrupt industries once thought safe from automation? Expect more (problematic) art-generating AI apps With the success of  Lensa , the AI-powered selfie app from Prisma Labs that went viral, you can expect...

How To Install Python on Windows 11

  Python programming is very simple and easy but to run any Python program you must have Python installed on your machine correctly. So without wasting any time let’s learn how to install python on Windows 11 machine Step 1: Download the Latest Version Of Python for Windows 11   1) Firstly we have to download the latest python version available on the internet. Follow the below provided downloading link and you’ll be redirected to the official python downloads page. There click on the yellow download button and Python will start getting downloading. Download Python Here :    https://www.python.org/downloads.   2) Once your download gets finished open it up in the folder where it has been downloaded and simply double click on the downloaded “ .exe ” file. If a small pop-up appears, there click on “ yes ” and your python installation wizard will start. Step 2: Install Python in Windows 11 1) Next, in the python installation wizard click on the “ Customize Installa...

Tether (cryptocurrency)

The most liquid, stable , and trusted stable coin . Launched in 2014 by a group of Bitcoin enthusiasts and early adopters, Tether is a blockchain -enabled platform designed to facilitate the use of fiat currencies digitally. Tether is a token backed by actual assets, including USD and Euros. One Tether equals one underlying unit of the currency backing it, e.g., the U.S. Dollar, and is backed 100% by actual assets in the Tether platform’s reserve account. Being anchored or “tethered” to real-world currency, Tether provides protection from the volatility of cryptocurrencies . Tether enables businesses — including exchanges, wallets, payment processors, financial services, and ATMs — to easily use fiat-backed tokens on blockchains . By leveraging Blockchain technology, Tether allows you to store, send and receive digital tokens person-to-person, globally, instantly, and securely for a fraction of the cost of alternatives. Tether’s platform is built to be fully transparent at all times....