{"id":16845,"date":"2024-04-15T19:24:00","date_gmt":"2024-04-15T13:54:00","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/"},"modified":"2024-10-14T23:53:09","modified_gmt":"2024-10-14T18:23:09","slug":"pattern-program-in-python-pyramid-pattern","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/","title":{"rendered":"Learn Pattern Program in Python - Examples and Code Explanation"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"what-are-pattern-programs-in-python\"><strong>What are Pattern Programs in Python?<\/strong><\/h2>\n\n\n\n<p>Patterns programs consist of alphabets, numbers or symbols in a particular structure. These programs enhance the logic, looping concepts and <a href=\"https:\/\/roboreachai.com\/how-to-build-industry-ready-coding-skills-in-2024\/\">coding skills<\/a>. They are primarily asked questions in the technical interviews in order to test a programmer's thinking and logic building skill. To be able to solve pattern questions, one must have a good knowledge of how the looping conditions work.<\/p>\n\n\n\n<p>As they are widely asked by interviewers whenever you go for a <a href=\"https:\/\/www.mygreatlearning.com\/blog\/python-developer-salary-in-india\/\" target=\"_blank\" rel=\"noreferrer noopener\">python developer <\/a>job or a software developer job, therefore, understanding the importance of this, we have come up with this article on \u201cPattern Program in Python\u201d.&nbsp;<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-title-link\">Python Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">In this course, you will learn the fundamentals of Python: from basic syntax to mastering data structures, loops, and functions. You will also explore OOP concepts and objects to build robust programs.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>11.5 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>51 Coding Exercises<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"number-pattern-problem\"><strong>Number Pattern Problem<\/strong><br><\/h2>\n\n\n\n<p>The pattern we want to form should look like as following<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1\n2 2\n3 3 3\n4 4 4 4\n5 5 5 5 5<\/pre>\n\n\n\n<p>Let\u2019s go ahead and see how can we print this pattern program in python:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>depth = 6\nfor number in range(depth):\n    for i in range(number):\n        print(number, end=\" \")\n    print(\" \")\n\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"code-explanation\"><strong>Code Explanation:<\/strong><\/h3>\n\n\n\n<p>We start off by initializing a variable called \u201cdepth\u201d and give it a value of 6 with the help of this command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;depth = 6<br><\/pre>\n\n\n\n<p>Going ahead, we have a nested for loop. We have the outer for loop to set the depth or number of rows in this pattern. When we use the command: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for number in range(depth):<\/pre>\n\n\n\n<p>This helps us to get a list of numbers 0-5. Because the depth value is 6, this means that 6 is exclusive and that is why the range goes from 0-5.<\/p>\n\n\n\n<p>Then, we set the inner for loop using this command:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> for i in range(number).<\/pre>\n\n\n\n<p>In the inner for loop, initially, the value of the number is 0, that is why we skip the first row. Then we go back to the outer for loop and the number value becomes 1. Once the number value is 1, we head inside the inner loop and print 1.<\/p>\n\n\n\n<p>After that number value is incremented again and it becomes 2, then we head to the inner loop and print 2 2.<\/p>\n\n\n\n<p>Similarly, we go back to the outer loop and this time number value becomes 3. After this inside the for loop, we print 3 3 3.<\/p>\n\n\n\n<p>Further which, again we go back to the outer loop, then the value of \u201cnumber\u201c becomes 4 and we print 4 4 4 4 with the inner loop.<\/p>\n\n\n\n<p>Finally, we will print 5 5 5 5 5.<br><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"incrementing-number-pattern-problem\"><strong>Incrementing Number Pattern Problem<\/strong><br><\/h2>\n\n\n\n<p> The pattern we want to form should look like as following <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1\n1 2\n1 2 3\n1 2 3 4\n1 2 3 4 5<\/pre>\n\n\n\n<p>Now, let\u2019s go ahead and see how can we have a sequence of numbers in each row with python:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>depth = 6\nfor number in range(1, depth):\n    for i in range(1, number + 1):\n        print(i, end=' ')\n    print(\"\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"code-explanation\"><strong>Code Explanation:<\/strong><br><\/h3>\n\n\n\n<p>We start off by initializing the value of depth to be 6. Then, we set the outer for loop with this command: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for number in range(1, depth)<\/pre>\n\n\n\n<p> With the help of this command, we create a range of numbers which go on from 1 to 5. Then, we go ahead and set the inner for loop with this command: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;for i in range(1, number + 1). <\/pre>\n\n\n\n<p>Inside the for loop, we print the digits using this command:&nbsp; <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(i, end=' ').<br><\/pre>\n\n\n\n<p>Initially, the value of the number is 1 in outer for loop, so we enter the inner for loop and go ahead and print 1.<\/p>\n\n\n\n<p>Then in the outer for loop, the value of number becomes 2, so we enter the inner for loop and we print 1 2.<\/p>\n\n\n\n<p>Similarly, we go back to the outer loop and here the number value becomes 3, so this time we enter the inner loop and print 1 2 3.<\/p>\n\n\n\n<p>Going ahead, the value of \u201cnumber\u201d in the outer loop becomes 4, so with the inner loop we print&nbsp;<\/p>\n\n\n\n<p>1 2 3 4<\/p>\n\n\n\n<p>And in the final iteration, we print out: 1 2 3 4 5<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"pyramid-pattern-problem-with-stars\"><strong>Pyramid Pattern Problem with Stars<\/strong><\/h2>\n\n\n\n<p>  The pattern we want to form should look like as following  <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">*\n* *\n* * *\n* * * *\n* * * * *<\/pre>\n\n\n\n<p>Let\u2019s see the code for this pattern program in python:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def diamond(n):\n    for m in range(0, n):\n        for i in range(0, m+1):\n            print(\"* \",end=\"\")\nprint(\"\\r\")\nn = 5\ndiamond(n)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"code-explanation\"><strong>Code Explanation:<\/strong><\/h3>\n\n\n\n<p>We start off by defining a method called \u201cdiamond\u201d with this command: def diamond(n).<\/p>\n\n\n\n<p>We set the outer for loop with this command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for m in range(0, n)<\/pre>\n\n\n\n<p> Then, we go ahead and set the inner for loop using this command: &nbsp; &nbsp; &nbsp; <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in range(0, m+1)<\/pre>\n\n\n\n<p>Initially, the value of\u2019 is 0 in the outer for loop, so we go inside the for loop and print *. Then, the value of\u2019 in the outer for loop becomes 1, this time we go inside the inner loop and print * *. Similarly, the value of\u2019 in the outer loop becomes 2, so, we go inside the inner loop and print&nbsp;* * *.<\/p>\n\n\n\n<p>Going ahead, the value of\u2019 is incremented in the outer loop and it becomes 3, so, with the inner loop, we print * * * *.In the final iteration, we print out * * * * *.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"inverted-semi-pyramid-pattern-problem-with-numbers\"><strong>Inverted Semi-Pyramid Pattern Problem with Numbers:<\/strong><\/h2>\n\n\n\n<p>  The pattern we want to form should look like as following  <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 1 1 1 1\n2 2 2 2\n3 3 3\n4 4\n5<\/pre>\n\n\n\n<p>Let\u2019s write the code for this:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>row = 5\na = 0\nfor i in range(row, 0, -1):\n    a += 1\n    for j in range(1, i + 1):\n        print(a, end=' ')\n    print('\\r')<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"code-explanation\"><strong>Code Explanation:<\/strong><\/h3>\n\n\n\n<p>We start off by initializing two variables. We set the value of row to be equal to 5 and the value of a to be equal to 0. After that we set the outer for loop with this command:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in range(row, 0, -1):<\/pre>\n\n\n\n<p>This outer for loop gives us numbers in descending order starting with 5 going on till 1. In the outer for loop, we increment the value of a with 1. After that, we set the inner for loop using this command: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for j in range(1, i + 1).<br><\/pre>\n\n\n\n<p>In the first iteration, the value of \u2018i\u2019 in outer for loop is 5, so with the inner for loop we print:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 1 1 1 1<\/pre>\n\n\n\n<p>In the second iteration, the value of \u2018i\u2019 in outer for loop is 4, so in the inner for loop we print:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">2 2 2 2<\/pre>\n\n\n\n<p>In the third iteration, the value of \u2018i\u2019 in the outer loop is decremented to 3, then, with the inner loop we print:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">3 3 3<\/pre>\n\n\n\n<p>Going ahead in the fourth iteration, the value of \u2018i\u2019 in the outer loop is decremented to 2, so this time with the inner loop, we print:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">2 2&nbsp;<\/pre>\n\n\n\n<p>And finally, in the last iteration, we print out 1.<br><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p> <strong><em><a rel=\"noreferrer noopener\" href=\"https:\/\/www.mygreatlearning.com\/blog\/python-tutorial-for-beginners-a-complete-guide\/\" target=\"_blank\">Basic tutorial for Python to get started<\/a><\/em><\/strong> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"inverted-semi-pyramid-pattern-problem-with-descending-order-of-numbers\"><strong>Inverted Semi-Pyramid Pattern Problem with Descending order of Numbers:<\/strong><\/h2>\n\n\n\n<p>  The pattern we want to form should look like as following  <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">5 5 5 5 5\n4 4 4 4\n3 3 3 \n2 2\n1<\/pre>\n\n\n\n<p>Let\u2019s look at the code to implement this pattern program in python:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>depth = 5\nfor i in range(depth, 0, -1):\n    n = i\n    for j in range(0, i):\n        print(n, end=' ')\n    print(\"\\r\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"code-explanation\"><strong>Code Explanation:<\/strong><\/h3>\n\n\n\n<p>We start off by initializing the value of depth to be equal to 5. Then using the outer for loop, we produce a list of numbers in descending order from 5 to 1. Inside the outer for loop, we set the value of n to be equal to i. After that, we start off the inner for loop using this command:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for j in range(0, i):\n<\/code><\/pre>\n\n\n\n<p>In the first iteration the value of \u2018i\u2019 is 5 in the outer loop, so with the inner loop we print: 5 5 5 5 5<\/p>\n\n\n\n<p>In the second iteration, the value of \u2018i\u2019 in the outer loop is decremented to 4, so we enter the inner loop and print 4 4 4 4<\/p>\n\n\n\n<p>Then in the third iteration, the value of \u2018i\u2019 becomes 3, so with the inner loop, we print: 3 3 3<\/p>\n\n\n\n<p>Going ahead in the fourth iteration, the value of \u2018i\u2019 becomes 2, this time we print out 2 2 with the inner loop.<\/p>\n\n\n\n<p>Finally, in the last iteration, the value of \u2018i\u2019 becomes 1 and we print out 1.<br><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"semi-pyramid-pattern-problem-with-numbers-descending-in-each-row\"><strong>Semi-Pyramid Pattern Problem with Numbers descending in each row:<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">1\n2 1\n3 2 1\n4 3 2 1\n5 4 3 2 1<\/pre>\n\n\n\n<p>Let\u2019s look at the code for this pattern program in python:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>size = 6\nfor row in range(1, size):\n    for column in range(row, 0, -1):\n        print(column, end=' ')\n    print(\"\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"code-explanation\"><strong>Code Explanation:<\/strong><\/h3>\n\n\n\n<p>We start off by setting the value of variable size to be equal to 6. Then, we set the outer for loop with this command: for row in range(1, size). With this outer for loop, we produce a list of numbers starting from 1 going on till 5. Then, we set the inner loop with this command: &nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for column in range(row, 0, -1)\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In the first iteration, the value of row is 1 in the outer loop, so we enter the inner for loop and print 1.<\/li>\n\n\n\n<li>Then in the second iteration, the value of row is 2 in the outer loop, so this time we enter the inner loop and print: 2 1<\/li>\n\n\n\n<li>After that, in the third iteration, the value of row becomes 3 in the outer loop, so in the inner loop we go ahead and print: 3 2 1<\/li>\n\n\n\n<li>Going ahead, in the fourth iteration, the value of row becomes 4 in the outer loop, so this time, in the inner loop we print: 4 3 2 1<\/li>\n\n\n\n<li>Finally, in the last iteration, we go ahead and print: 5 4 3 2 1<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"alphabet-pattern-programs-in-python\"><strong>Alphabet Pattern Programs in Python <\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"triangle-patterns\"><strong>Triangle Patterns<\/strong><\/h4>\n\n\n\n<p>a) Pattern:-<\/p>\n\n\n\n<p><strong>A<br>BC<br>DEF<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The initial value set to 65 because the ASCII value of A is 65<\/li>\n\n\n\n<li>Outer loop decide no. of rows<\/li>\n\n\n\n<li>char() function convert no. to their corresponding value of ASCII letter<\/li>\n<\/ul>\n\n\n\n<p>Code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>initialValue = 65\nfor i in range(0, 6):\n    for j in range(0, i + 1):\n     # It will convert the ASCII value to the character\n         alphabate = chr(initialValue)\n         # print(alphabate, end=' ')\n         print(f\"{alphabate}\", end=\"\")\n         initialValue += 1\n    print(\"\")<\/code><\/pre>\n\n\n\n<p>Output: <\/p>\n\n\n<figure class=\"wp-block-image size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-3.png\"><img decoding=\"async\" width=\"481\" height=\"472\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-3.png\" alt=\"pattern program in python\" class=\"wp-image-35290\" style=\"width:238px;height:230px\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-3.png 481w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-3-300x294.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-3-428x420.png 428w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-3-150x147.png 150w\" sizes=\"(max-width: 481px) 100vw, 481px\" \/><\/figure>\n\n\n\n<p>b) Pattern:-<\/p>\n\n\n\n<p><strong>A<br>BB<br>CCC<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Defining a variable called num with a value of 65(65 =&gt; A).<\/li>\n\n\n\n<li>The outer loop ranges from 0 to 5, which means the loop will run 5 times, and the inner loop will increment by 1.<\/li>\n\n\n\n<li>char function converts ASCII number to the corresponding character.<\/li>\n\n\n\n<li>Print with f string.<\/li>\n\n\n\n<li>print(\u201c\\r\u201d) stands for a line break.<\/li>\n<\/ul>\n\n\n\n<p>Code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># defining A = 65\n#num = A\nnum = 65 \nfor i in range(0, 5):\n    for j in range(0, i + 1):\n        char = chr(num)\n        # printing char value\n        print(f\"{char} \", end=\"\")\n    # incrementing number\n    num = num + 1\n    # ending line after each row\n    print(\"\\r\")\n<\/code><\/pre>\n\n\n\n<p>Output: <\/p>\n\n\n<figure class=\"wp-block-image size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-4.png\"><img decoding=\"async\" width=\"395\" height=\"421\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-4.png\" alt=\"triangle pattern\" class=\"wp-image-35291\" style=\"width:293px;height:307px\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-4.png 395w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-4-281x300.png 281w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-4-150x160.png 150w\" sizes=\"(max-width: 395px) 100vw, 395px\" \/><\/figure>\n\n\n\n<p><strong>c) Right-Angled Triangle Pattern with Same Character<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Initializing a function with name <strong>letter_range<\/strong> in which 2 arguments will pass one is started (where you want to start) end(where you want to end).<\/li>\n\n\n\n<li>The inner loop will increment value by 1 and print the character after that a line break.<\/li>\n<\/ul>\n\n\n\n<p>Pattern:-<\/p>\n\n\n\n<p><strong>A<br>AB<br>ABC<\/strong><\/p>\n\n\n\n<p>Code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># initializing function letter_range\n\ndef letter_range(start, end):\n  \t# outer loop\n    for i in range(start, end):\n        # inner loop\n        for j in range(65, i + 1):\n            print(f\"{chr(j)}\", end=\"\")\n        print()\n\n# calling Function\nletter_range(65, 75)<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>d) Pattern:-<\/p>\n\n\n\n<p>A B C D E<br>B C D E<br>C D E<br>D E<br>E<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Initializing a function with the name <strong>alpha,<\/strong> which takes an integer value.<\/li>\n\n\n\n<li>In the outer loop, we use for in loop for iteration, which goes from 1, n+1.<\/li>\n\n\n\n<li>The inner loop goes from i, n + 1 where i = current value of outer loop iteration.<\/li>\n\n\n\n<li>Using ord() function to return Unicode character. For example print(ord('B'))&nbsp; -&gt;&nbsp; # 66.<\/li>\n\n\n\n<li>Every time the inner loop exits, we use the print() function for spacing.<\/li>\n<\/ul>\n\n\n\n<p>Code: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># defining Function alpha\ndef alpha(n):\n    for i in range(1, n + 1):\n        for j in range(i, n + 1):\n            print(chr(ord('A') - 1 + j), end=' ')\n        print()\n\n# calling function\nalpha(5)\n<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-5.png\"><img decoding=\"async\" width=\"264\" height=\"227\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-5.png\" alt=\"Pattern program in python\" class=\"wp-image-35440\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-5.png 264w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-5-150x129.png 150w\" sizes=\"(max-width: 264px) 100vw, 264px\" \/><\/figure>\n\n\n\n<p>e) Pattern:<\/p>\n\n\n\n<p>A A A A A<br>B B B B<br>C C C<br>D D<br>E<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Initializing and declaring variables with the value of i = 0, j = 0, n = 5.<\/li>\n\n\n\n<li>Using for in loop within a range of 1, n+1 where n = 5<\/li>\n\n\n\n<li>Also, passing the third argument (-1) in for loop<\/li>\n\n\n\n<li>ord() function is added which returns a Unicode character.\n<ul class=\"wp-block-list\">\n<li>For example print(ord('C'))&nbsp; -&gt;&nbsp; # 67.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>Code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># patterns of alphabets\ni = 0\nj = 0\nn = 5\nfor i in range(1, n + 1):\n    for j in range(n, i - 1, -1):\n        print(chr(ord('A') - 1 + i), end=\" \")\n    print(\"\")\n<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-6.png\"><img decoding=\"async\" width=\"288\" height=\"219\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-6.png\" alt=\"triangle pattern\" class=\"wp-image-35444\" style=\"width:230px;height:171px\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-6.png 288w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-6-80x60.png 80w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-6-150x114.png 150w\" sizes=\"(max-width: 288px) 100vw, 288px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"star-pattern-in-python\"><strong>Star Pattern in Python<\/strong><\/h2>\n\n\n\n<p>a) <strong>Diamond Pattern in Python: <\/strong>It like a diamond star pyramid. Basically, it is made by two upper and lower equilateral pyramid and just connected by their mouth&nbsp;<\/p>\n\n\n\n<p>Code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>n = int(input('Enter the number:'))\nk = 2 * n - 2\nfor i in range(0, n):\n    for j in range(0, k):\n        print(end= ' ')\n    k = k - 1\n    for j in range(0, i + 1):\n        print('* ', end= '') # No space \n    print('') # No space\n    \nk = n - 2\nfor i in range(n, -1, -1):\n    for j in range(k, 0, -1):\n        print(end= ' ')\n    k = k + 1\n    for j in range(0, i + 1):\n        print('* ', end= '') # No space\n    print('') # No space\n<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-7.png\"><img decoding=\"async\" width=\"361\" height=\"547\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-7.png\" alt=\"diamond pattern\" class=\"wp-image-35452\" style=\"width:241px;height:362px\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-7.png 361w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-7-198x300.png 198w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-7-277x420.png 277w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-7-150x227.png 150w\" sizes=\"(max-width: 361px) 100vw, 361px\" \/><\/figure>\n\n\n\n<p>b) <strong>Sandglass pattern of star: <\/strong>X like pyramid of star, where basically upper equilateral pyramid and lower equilateral pyramids are connected.<\/p>\n\n\n\n<p>code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>n = int(input('Enter the number:'))\ni = 0\nwhile i &lt;= n - 1:\n    j = 0\n    while j &lt; i:\n        # display space\n        print('', end= ' ')\n        j += 1\n    k = i\n    while k &lt;= n - 1:\n        print('*', end= ' ')\n        k += 1\n    print()\n    i += 1\n\ni = n - 1\nwhile i &gt;= 0:\n    j = 0\n    while j &lt; i:\n        print('', end= ' ')\n        j += 1\n    k = i\n    while k &lt;=  n - 1:\n        print('*', end= ' ')\n        k += 1\n    print('')\n    i -= 1\n<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-8.png\"><img decoding=\"async\" width=\"370\" height=\"482\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-8.png\" alt=\"\" class=\"wp-image-35453\" style=\"width:264px;height:338px\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-8.png 370w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-8-230x300.png 230w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-8-322x420.png 322w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-8-150x195.png 150w\" sizes=\"(max-width: 370px) 100vw, 370px\" \/><\/figure>\n\n\n\n<p>c) <strong>Empty diamond pattern: <\/strong>It is as similar as the diamond like pattern but not any object into the pyramid.&nbsp;<\/p>\n\n\n\n<p>Code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>n = int(input('Enter the number:'))\ni = 1\nwhile i &lt;= n:\n    j = n\n    while j &gt; i:\n        # display space\n        print(' ', end= ' ')\n        j -= 1\n    print('* ', end= ' ')\n    k = 1\n    while k &lt; 2 * (i - 1):\n        print(' ', end= ' ')\n        k += 1\n    if i == 1:\n        print()\n    else:\n        print('* ')\n    i += 1\n\ni = n - 1\nwhile i &gt;= 1:\n    j = n\n    while j &gt; i:\n        print(' ', end= ' ')\n        j -= 1\n    print('* ', end= ' ')\n    k = 1\n    while k &lt; 2 * (i - 1):\n        print(' ', end= ' ')\n        k += 1\n    if i == 1:\n        print( )\n    else:\n        print('*')\n    i -= 1\n<\/code><\/pre>\n\n\n\n<p>Output: <\/p>\n\n\n<figure class=\"wp-block-image size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-9.png\"><img decoding=\"async\" width=\"447\" height=\"443\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-9.png\" alt=\"diamond pattern\" class=\"wp-image-35462\" style=\"width:241px;height:233px\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-9.png 447w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-9-300x297.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-9-150x149.png 150w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-9-424x420.png 424w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-9-96x96.png 96w\" sizes=\"(max-width: 447px) 100vw, 447px\" \/><\/figure>\n\n\n\n<p>d) <strong>Square pattern: <\/strong>The program will take the length of the side as input and print the pattern of a square.<\/p>\n\n\n\n<p>code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>n = int(input('Enter the number:'))\nfor i in range(n):\n    for j in range(n):\n        print('* ', end= '')\n    print()<\/code><\/pre>\n\n\n\n<p>Output: <\/p>\n\n\n<figure class=\"wp-block-image size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-33.png\"><img decoding=\"async\" width=\"451\" height=\"306\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-33.png\" alt=\"square pattern\" class=\"wp-image-36881\" style=\"width:272px;height:176px\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-33.png 451w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-33-300x204.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-33-150x102.png 150w\" sizes=\"(max-width: 451px) 100vw, 451px\" \/><\/figure>\n\n\n\n<p>e) <strong>Rectangle pattern: <\/strong>The program will take the length &amp; breadth as input and print the rectangle pattern.<\/p>\n\n\n\n<p>code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rows = int(input('Enter the number for rows:'))\ncolumns = int(input('Enter the number for columns:'))\nfor i in range(rows):\n    for j in range(columns):\n        print('* ', end= '')\n    print('')\n<\/code><\/pre>\n\n\n\n<p>Output: <\/p>\n\n\n<figure class=\"wp-block-image size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-34.png\"><img decoding=\"async\" width=\"663\" height=\"239\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-34.png\" alt=\"rectangle pattern\" class=\"wp-image-36884\" style=\"width:418px;height:145px\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-34.png 663w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-34-300x108.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/image-34-150x54.png 150w\" sizes=\"(max-width: 663px) 100vw, 663px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Python for Data Science Full Course | Data Science Tutorials for Beginners in 2022 | Great Learning\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/JDcZBzb46ts?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faqs\"><strong>FAQs<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"q1-how-do-you-create-a-pattern-in-python\"><strong>Q1 How do you create a pattern in Python?<\/strong><\/h4>\n\n\n\n<p>The for loop is used to print various patterns in python. Various patterns use multiple for loops using the following concept:<\/p>\n\n\n\n<ol style=\"list-style-type:1\" class=\"wp-block-list\">\n<li>outer loop: prints the number or rows<\/li>\n\n\n\n<li>inner loop: prints the number of columns and inner nested loops<\/li>\n\n\n\n<li>variable: to print whitespaces according to the requirement of the code.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"q2-what-is-a-pattern-in-python\"><strong>Q2 What is a pattern in Python?<\/strong><\/h4>\n\n\n\n<p>Patters in python are printed using for loops. Different numeric, alphabetic or symbolic patterns can be formed using these loops by manipulating values or print statements according to the question to find the right solution.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"q3-how-do-i-learn-a-python-pattern-program\"><strong>Q3 How do I learn a python pattern program?<\/strong><\/h4>\n\n\n\n<p>Steps:<\/p>\n\n\n\n<p>1. Decision: Take the decision of how many rows and columns are required. The nested loops are used to print any pattern in python. For letting the user decide the size of the pattern, the \"input()\" function is used.<\/p>\n\n\n\n<p>2. Iteration<\/p>\n\n\n\n<p>(i) Rows: outer loop is iterated for the number of rows using the \"for\" loop and \"range()\" function.<\/p>\n\n\n\n<p>(ii) Columns: outer loop is iterated for the number of columns depending on the values of the outer loop.<\/p>\n\n\n\n<p>3. Print: \"print()\" function is iterated in each nested \"for\" loop to display&nbsp; different patterns<\/p>\n\n\n\n<p>4. Adding a new line: A new line is added after each iteration of the outer loop using the \"print()\" function to appropriately display the pattern.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"q4-what-does-r-mean-in-python\"><strong>Q4 What does \"R\" mean in Python?<\/strong><\/h4>\n\n\n\n<p>\"R\" or \"r\" is used as a prefix for string literals to create raw strings. Standard strings treat backslash (\\) as a literal character. Using \"r\" or \"R\" is useful when we want to use backlash as a part of the string instead of an escape character.<br>Example: Executing a string with an escape character<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a='We\\nRun'\nprint(a)<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>We\nRun<\/code><\/pre>\n\n\n\n<p>Example: Executing a string using \"r\" (raw string)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>raw_a = r'We\\nRun'\nprint(raw_a)<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>We\\nRun<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"q5-what-does-end-do-in-python\"><strong>Q5 What does end =' do in Python?<\/strong><\/h4>\n\n\n\n<p>The print() function is a function that, by default, adds a new line at the end. By using ',' at the end, it can be suppressed in Python 2.<br>Example: print b,<br>Whereas in Python 3, \"end=' \" is appended to add a space in place of a new line.<br>Example: print(b, end=\" \")<\/p>\n\n\n\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"How do you create a pattern in Python?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"The for loop is used to print various patterns in python. Various patterns use multiple for loops using the following concept:\n\nouter loop: prints the number or rows\ninner loop: prints the number of columns and inner nested loops\nvariable: to print whitespaces according to the requirement of the code.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What is a pattern in Python?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Patters in python are printed using for loops. Different numeric, alphabetic or symbolic patterns can be formed using these loops by manipulating values or print statements according to the question to find the right solution.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"How do I learn a python pattern program?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Steps:\n\n1. Decision: Take the decision of how many rows and columns are required. The nested loops are used to print any pattern in python. For letting the user decide the size of the pattern, the \u201cinput()\u201d function is used.\n\n2. Iteration\n\n(i) Rows: outer loop is iterated for the number of rows using the \u201cfor\u201d loop and \u201crange()\u201d function.\n\n(ii) Columns: outer loop is iterated for the number of columns depending on the values of the outer loop.\n\n3. Print: \u201cprint()\u201d function is iterated in each nested \u201cfor\u201d loop to display  different patterns\n\n4. Adding a new line: A new line is added after each iteration of the outer loop using the \u201cprint()\u201d function to appropriately display the pattern.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What does end =\u2019 do in Python?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"The print() function is a function that, by default, adds a new line at the end. By using \u2018,\u2019 at the end, it can be suppressed in Python 2.\"\n    }\n  }]\n}\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>What are Pattern Programs in Python? Patterns programs consist of alphabets, numbers or symbols in a particular structure. These programs enhance the logic, looping concepts and coding skills. They are primarily asked questions in the technical interviews in order to test a programmer's thinking and logic building skill. To be able to solve pattern questions, [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":16911,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36796],"content_type":[36248],"class_list":["post-16845","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-python","content_type-career-guide"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to make Python Pattern? Pattern Program in Python<\/title>\n<meta name=\"description\" content=\"Patterns programs consist of alphabets, numbers or symbols in a particular structure.These programs enhance the logic, looping concepts and coding skills.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn Pattern Program in Python - Examples and Code Explanation\" \/>\n<meta property=\"og:description\" content=\"Patterns programs consist of alphabets, numbers or symbols in a particular structure.These programs enhance the logic, looping concepts and coding skills.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-04-15T13:54:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-14T18:23:09+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"750\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Learn Pattern Program in Python - Examples and Code Explanation\",\"datePublished\":\"2024-04-15T13:54:00+00:00\",\"dateModified\":\"2024-10-14T18:23:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/\"},\"wordCount\":2085,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/shutterstock_794376475.jpg\",\"keywords\":[\"python\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/\",\"name\":\"How to make Python Pattern? Pattern Program in Python\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/shutterstock_794376475.jpg\",\"datePublished\":\"2024-04-15T13:54:00+00:00\",\"dateModified\":\"2024-10-14T18:23:09+00:00\",\"description\":\"Patterns programs consist of alphabets, numbers or symbols in a particular structure.These programs enhance the logic, looping concepts and coding skills.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/shutterstock_794376475.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/shutterstock_794376475.jpg\",\"width\":1000,\"height\":750,\"caption\":\"pattern program in python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/pattern-program-in-python-pyramid-pattern\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Learn Pattern Program in Python &#8211; Examples and Code Explanation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to make Python Pattern? Pattern Program in Python","description":"Patterns programs consist of alphabets, numbers or symbols in a particular structure.These programs enhance the logic, looping concepts and coding skills.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/","og_locale":"en_US","og_type":"article","og_title":"Learn Pattern Program in Python - Examples and Code Explanation","og_description":"Patterns programs consist of alphabets, numbers or symbols in a particular structure.These programs enhance the logic, looping concepts and coding skills.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2024-04-15T13:54:00+00:00","article_modified_time":"2024-10-14T18:23:09+00:00","og_image":[{"width":1000,"height":750,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Learn Pattern Program in Python - Examples and Code Explanation","datePublished":"2024-04-15T13:54:00+00:00","dateModified":"2024-10-14T18:23:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/"},"wordCount":2085,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg","keywords":["python"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/","url":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/","name":"How to make Python Pattern? Pattern Program in Python","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg","datePublished":"2024-04-15T13:54:00+00:00","dateModified":"2024-10-14T18:23:09+00:00","description":"Patterns programs consist of alphabets, numbers or symbols in a particular structure.These programs enhance the logic, looping concepts and coding skills.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg","width":1000,"height":750,"caption":"pattern program in python"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/pattern-program-in-python-pyramid-pattern\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Learn Pattern Program in Python &#8211; Examples and Code Explanation"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg",1000,750,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475-300x225.jpg",300,225,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475-768x576.jpg",768,576,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg",1000,750,false],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg",1000,750,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg",1000,750,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg",640,480,false],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg",96,72,false],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/shutterstock_794376475.jpg",150,113,false]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"What are Pattern Programs in Python? Patterns programs consist of alphabets, numbers or symbols in a particular structure. These programs enhance the logic, looping concepts and coding skills. They are primarily asked questions in the technical interviews in order to test a programmer's thinking and logic building skill. To be able to solve pattern questions,&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=16845"}],"version-history":[{"count":50,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16845\/revisions"}],"predecessor-version":[{"id":109144,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16845\/revisions\/109144"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/16911"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=16845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=16845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=16845"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=16845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}