Python Basics

How to make python print something multiple times?

Python has print function which prints the passed argument. And in some cases we may want to print a message multiple times.

If we want to print something multiple times then for loop is an easy option.

for _ in range(0,10):

print(“hello friend”)

Output:

hello friend

hello friend

hello friend

hello friend

hello friend

hello friend

hello friend

hello friend

hello friend

hello friend

The above for loop prints the message ten times.

There might be a situation where you may want to print a message repetitively at different places of a python script.

Then you can define a function which prints the message and call where ever you have the requirement.

function PrintMessage():

print(“hello friend”)

when ever you call the function it will print: hello friend.