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 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 in 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 traditional business networks Permissions Blockchains can be permissioned or permissionles...

What is Boxing Day

  Boxing Day is a holiday that is celebrated on December 26th in several countries, including Canada, the United Kingdom, Australia, and New Zealand. It is a public holiday that traditionally follows Christmas Day and is often a day off work for many people. The origins of the holiday are not definitively known, but it may have originated as a day for servants and tradespeople to receive gifts from their employers or as a way for the wealthy to give back to the less fortunate. In modern times, Boxing Day is often celebrated with activities such as shopping, sports events, and visiting with friends and family.

25 reasons why Python may be a good choice for your project

Python is a high-level, general-purpose programming language, which means it can be used to build almost any type of software, from desktop applications to web apps to scientific applications and more. Python is easy to learn and use, with a simple syntax and a large standard library that supports many common programming tasks. Python is a dynamically-typed language, which means you don't need to specify the type of a variable when you declare it. This makes it easy to get started with Python and can save time when writing code. Python has a large and active community of users and developers, which means there is a wealth of documentation, libraries, and tools available to help you get started with your project. Python has a large number of third-party libraries and frameworks available, which can make it easier to develop complex applications quickly. Python has a number of built-in data types, such as lists, dictionaries, and tuples, which can be used to store and manipulate data...