Python

Python Print Function

Python Print Function

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:

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 (“\n\n\n\n\n\n”)

or you can also write it as

print (6* “\n”)

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.

Asenna uusin Dolphin Emulator for Gamecube & Wii Linuxiin
Dolphin-emulaattorin avulla voit pelata valitsemiasi Gamecube & Wii -pelejä Linux-henkilökohtaisilla tietokoneilla (PC). Koska Dolphin Emulator on va...
Kuinka käyttää GameConqueror-huijausmoottoria Linuxissa
Artikkelissa on opas GameConqueror-huijausmoottorin käytöstä Linuxissa. Monet Windows-pelejä pelaavat käyttäjät käyttävät "Cheat Engine" -sovellusta m...
Parhaat pelikonsoliemulaattorit Linuxille
Tässä artikkelissa luetellaan suositut pelikonsolin emulointiohjelmistot, jotka ovat saatavana Linuxille. Emulointi on ohjelmistojen yhteensopivuusker...