{"id":13254,"date":"2021-09-30T12:30:15","date_gmt":"2021-09-30T07:00:15","guid":{"rendered":"https:\/\/python-programs.com\/?p=13254"},"modified":"2021-11-22T18:34:38","modified_gmt":"2021-11-22T13:04:38","slug":"python-program-to-print-a-string-n-number-of-times","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-a-string-n-number-of-times\/","title":{"rendered":"Python Program to Print a String N Number of Times"},"content":{"rendered":"
Given a string and the number n the task is to print the given string n number of times in Python.<\/p>\n
Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to print the given string n number of times in Python.<\/p>\n The best and excellent way to learn a java programming language is by practicing Simple Java Program Examples<\/a> as it includes basic to advanced levels of concepts.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Given a string and the number n the task is to print the given string n number of times in Python. Examples: Example1: Input: Given string = ‘BTechgeeks ‘ Given number of times = 11 Output: Printing the given string [ BTechgeeks ] 11 number of times : BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks …<\/p>\nGiven string = 'BTechgeeks '\r\nGiven number of times = 11<\/pre>\n
Printing the given string [ BTechgeeks ] 11 number of times :\r\nBTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks<\/pre>\n
Given string = 'aplustopper '\r\nGiven number of times = 8<\/pre>\n
Printing the given string [ aplustopper ] 8 number of times :\r\naplustopper aplustopper aplustopper aplustopper aplustopper aplustopper aplustopper aplustopper<\/pre>\n
Program to Print a String N Number of Times in Python<\/h2>\n
\n
Method #1: Using For Loop (Static Input)<\/h3>\n
\n
# Give the string as static input and store it in a variable.\r\ngvnstrng = 'BTechgeeks'\r\n# Give the number of times the string to be printed\r\n# as static input and store it in another variable.\r\nnumbtimes = 11\r\nprint('Printing the given string [', gvnstrng, ']', numbtimes,'number of times :')\r\n# Loop till a given number of times using the For loop.\r\nfor times in range(numbtimes):\r\n # Inside the For loop print the given string using the print() statement.\r\n print(gvnstrng, end=' ')\r\n<\/pre>\n
Printing the given string [ BTechgeeks ] 11 number of times :\r\nBTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks<\/pre>\n
Method #2: Using For Loop (User Input)<\/h3>\n
\n
# Give the string as user input using the input()\r\n# function and store it in a variable.\r\n\r\ngvnstrng = input('Enter some random string to be printed = ')\r\n# Give the number of times the string to be printed as user input using the int(input()) function\r\n# and store it in another variable.\r\nnumbtimes = int(\r\n input('Enter some random number of times the string to be printed = '))\r\nprint('Printing the given string [', gvnstrng,\r\n ']', numbtimes, 'number of times :')\r\n# Loop till a given number of times using the For loop.\r\nfor times in range(numbtimes):\r\n # Inside the For loop print the given string using the print() statement.\r\n print(gvnstrng, end=' ')\r\n<\/pre>\n
Enter some random string to be printed = AplusTopper\r\nEnter some random number of times the string to be printed = 8\r\nPrinting the given string [ AplusTopper ] 8 number of times :\r\nAplusTopper AplusTopper AplusTopper AplusTopper AplusTopper AplusTopper AplusTopper AplusTopper<\/pre>\n
Method #3: Using * Operator (Static Input)<\/h3>\n
\n
# Give the string as static input and store it in a variable.\r\ngvnstrng = 'BTechgeeks '\r\n# Give the number of times the string to be printed\r\n# as static input and store it in another variable.\r\nnumbtimes = 11\r\nprint('Printing the given string [', gvnstrng,\r\n ']', numbtimes, 'number of times :')\r\n#Print\u00a0the\u00a0given\u00a0string\u00a0given\u00a0the\u00a0number\u00a0of\u00a0times\u00a0using\u00a0the\u00a0*\u00a0operator.\r\nprint(gvnstrng*numbtimes)\r\n<\/pre>\n
Printing the given string [ BTechgeeks ] 11 number of times :\r\nBTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks BTechgeeks<\/pre>\n
Method #4: Using * Operator (User Input)<\/h3>\n
\n
# Give the string as user input using the input()\r\n# function and store it in a variable.\r\n\r\ngvnstrng = input('Enter some random string to be printed = ')\r\n# Give the number of times the string to be printed as user input using the int(input()) function\r\n# and store it in another variable.\r\nnumbtimes = int(\r\n input('Enter some random number of times the string to be printed = '))\r\nprint('Printing the given string [', gvnstrng,\r\n ']', numbtimes, 'number of times :')\r\n# Print the given string given the number of times using the * operator.\r\nprint(gvnstrng*numbtimes)\r\n<\/pre>\n
Enter some random string to be printed = aplustopper \r\nEnter some random number of times the string to be printed = 8\r\nPrinting the given string [ aplustopper ] 8 number of times :\r\naplustopper aplustopper aplustopper aplustopper aplustopper aplustopper aplustopper aplustopper<\/pre>\n
\n