34 C
Jaipur
Tuesday, October 20, 2020

Python Print Function – Linux Hint

Must read

Mi Watch Color Sports Edition with Blood Oxygen Monitoring Launched in China

Xiaomi unveiled the Mi Watch Color in China earlier this year. It has since found its way to India as the Mi Watch Revolve....

5 Best GoPro Hero 9 Black Lens Mods and Filters to Buy

GoPro Hero 9 Black is one of the finest action cameras on the market right now. It brings 5K recording, multiple shooting modes, new...

Nokia Essential Wireless Headphones E1200 with 40-Hour Battery Life Launched

First unveiled in China earlier last month, HMD Global is now set to make its latest audio accessories available in the global market.  The...

Phishing Attackers Preferred Microsoft More Than Other Brands

A new report from CheckPoint security reveals that Microsoft was the most impersonated brand by attackers trying to steal people’s account details and payment information.Usually, a...

Python is one of the modern, multi-purpose, and high-level programming languages. Python is used for various purposes i.e. software development, data science, machine learning, artificial intelligence, deep learning, and back end development. More often, in any programming language, we need to print some data or string on the console. In python, we use the print () function to print the string or any kind of data on the console.

In this article, we will see how we can use the print () function in python for printing purposes.

Let’s begin this article by printing the hello world in python.

To print the Hello World in python 3, make use of the print () function as follows:

And the output is

Unlike in python 2, we do not use parenthesis with the print function. In python 2 it would be like this

And the output is

Furthermore, in this article, we will follow the python 3 syntax.

Let’s print the “Welcome to LinuxHint” by using the print function.

print(“Welcome to LinuxHint”)

Output

Print name of the Animals

If you want to print the name of the animals, you can print in the following way:

print (“Cow”)
print(“Dog”)
print(“Cat”)
print(“Lion”)

Output


This is the basic syntax of the print () function. We can use multiple parameters with the print function. The following are the parameters of the print () function:

  • Objects: Objects indicate the objects that are to be printed in the print () function.
  • Sep: It is used to separate the objects in the print function. We can use ‘,’ as a sep. the default value of sep is ‘’.
  • End: In python, the print function end by default with a new line ‘n’. You can use any value to end the python print function.

Print multiple objects in one print statement

Consider the animal example that we used previously to print the name of animals. Previously we used multiple print statements to print the name of animals. In this example, we print the name of various animals in a single print statement. The animals are objects. The objects are separated by a sep which is ‘,’.

print(“Cow”,“Dog”,“Cat”,“Lion”, sep =‘,’)

In the above line of code cow, dog, cat, and lion are the objects, and ‘,’ is a separator.

Output

Print statement with end parameter

As we know, the print statement end with a new line by default but we can use any value to end the python print statement. We can end a line with any string or character. Python 2 does not support it.

For example, the print statement ends with ‘!’.

print (“Hello Everyone”, end = ‘ ‘)
print (“Welcome to the LinuxHint”, end = ‘!’)

Output

The print statement end with ‘@’

print (“An email must contain”, end = ‘@’)

Output

Print blank lines

Python allows us to print the blank lines in the print () function. Sometimes we need to print the blank lines. To print the blank lines we use ‘/n’ in python.

Example

Print 6 blank lines. You can write it as follows:

print (“nnnnnn”)

or you can also write it as

Code example

print (“Hello Everyone”)
print (6*n)
print (“Welcome to the LinuxHint”)

Output

Conclusion

The print () function is used for printing the strings, objects, characters, and it is also used for debugging purposes. In this article, we have explained the python print () function and its usage with multiple examples.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

Mi Watch Color Sports Edition with Blood Oxygen Monitoring Launched in China

Xiaomi unveiled the Mi Watch Color in China earlier this year. It has since found its way to India as the Mi Watch Revolve....

5 Best GoPro Hero 9 Black Lens Mods and Filters to Buy

GoPro Hero 9 Black is one of the finest action cameras on the market right now. It brings 5K recording, multiple shooting modes, new...

Nokia Essential Wireless Headphones E1200 with 40-Hour Battery Life Launched

First unveiled in China earlier last month, HMD Global is now set to make its latest audio accessories available in the global market.  The...

Phishing Attackers Preferred Microsoft More Than Other Brands

A new report from CheckPoint security reveals that Microsoft was the most impersonated brand by attackers trying to steal people’s account details and payment information.Usually, a...

How to install ONLYOFFICE Workspace on Ubuntu

ONLYOFFICE Workspace is a free open-source self-hosted solution for team management and collaboration which includes:ONLYOFFICE Docs - online editors for documents, spreadsheets, and presentations...