Piton

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.

Jocuri HD remasterizate pentru Linux care nu au avut niciodată lansare Linux mai devreme
Mulți dezvoltatori și editori de jocuri vin cu remasterizarea HD a jocurilor vechi pentru a prelungi durata de viață a francizei, vă rog fanilor să so...
Cum se utilizează AutoKey pentru automatizarea jocurilor Linux
AutoKey este un utilitar de automatizare desktop pentru Linux și X11, programat în Python 3, GTK și Qt. Folosind funcțiile sale de scriptare și MACRO,...
Cum se arată FPS Counter în jocurile Linux
Jocurile cu Linux au primit un impuls major când Valve a anunțat suportul Linux pentru clientul Steam și jocurile acestora în 2012. De atunci, multe j...