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 IS ETHEREUM?

  Ethereum is open access to digital money and data-friendly services for everyone — no matter your background or location. It’s a community-built technology behind the   cryptocurrency   ether (ETH) and thousands of applications you can use today. Banking for everyone : Not everyone has access to financial services. But all you need to access Ethereum and its lending, borrowing, and savings products is an internet connection. A more private internet:  You don’t need to provide all your personal details to use an Ethereum app. Ethereum is building an economy based on value, not surveillance. A peer-t o -peer network:  Ethereum allows you to move money, or make agreements, directly with someone else. You don’t need to go through intermediary companies. Censorship-resistant:  No government or company has control over Ethereum. This decentralization makes it nearly impossible for anyone to stop you from receiving payments or using services on Ethereum. Commerc...

What Makes a Blockchain Suitable for Business?

  Instead of having a   blockchain   that relies on the exchange of   cryptocurrencies   with anonymous users on a public network (as is the case with   bitcoin ), a   blockchain   for business is a private, permissioned network with known identities and without the need for   cryptocurrencies . To further understand how a  blockchain  for business works, and to appreciate its potential for revolutionizing business networks, you need to understand the four key concepts of  blockchain  for business These four concepts are explained in this section. Shared ledger they’ve been used i n  double-entry bookkeeping since the 13th century. What is new is the concept of a shared, distributed ledger — an immutable record of all transactions on the network, a record that all network participants can access. With a shared ledger, transactions are recorded only once, eliminating the duplication of effort that’s typical of traditio...

Newcastle United F.C. Leicester City F.C. Premier League • EFL

  Newcastle United F.C. is a professional football club based in Newcastle upon Tyne, England. The club currently competes in the Premier League, the top division of English football. Newcastle United has a long and successful history, having won four top-flight English league titles and six FA Cups. Leicester City F.C. is a professional football club based in Leicester, England. The club currently competes in the Premier League and has a strong history of success, having won the top-flight English league title in the 2015-2016 season and the EFL Cup in the 1997-1998 season. The Premier League is the top division of English football and is widely regarded as one of the best football leagues in the world. It is made up of 20 clubs and is contested annually, with the winner being crowned the champion. The EFL (English Football League) is the governing body for professional football in England. It is made up of 72 clubs, which are divided into three divisions: the Championship, League...