How do you print a string 3 times in Python?

In this code, we will see how to print a string 3 times in Python

Using just print() function

str = "Hello World "
print(str * 3) 
#Hello World Hello World Hello World 

Using for loop:

str = "Hello World"
for i in range(3):
    print(str)

#Hello World
#Hello World
#Hello World

Using while loop:

str = "Hello World"
i = 1
while(i<4):
    print(str)
    i = i + 1

#Hello World
#Hello World
#Hello World
Facebook
Twitter
LinkedIn
Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

ABOUT ME !!
Johan William

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

RECENT POSTS

TEST