Pattern Program in PythonLast Updated : 6 Jan 2026 Python pattern program enhances the coding skill, logic, and looping concepts. These are usually asked in Python interview to check the logic and thinking of the programmer. We can print a Python pattern program in different designs. To learn the pattern program, we must have a deep knowledge of the Python loop, such as for loop do-while loop. ![]() We have classified the Python pattern program into three categories:
Before moving to the pattern programs, let's see the approach. Whenever you design logic for a pattern program, first draw that pattern in the blocks, as we have shown in the following image. The figure presents a clear look of the pattern. Each pattern program has two or more loops. The number of the loop depends on the complexity of pattern or logic.
![]() Printing Star PatternsRight Triangle Star PatternA Right Triangle Star Pattern is a basic pattern printing concept that helps in logic building. It consists of stars that form a 90-degree right-angled triangle. Let’s see a simple example learning how to print a right-angled Triangle ExampleCompile and RunOutput: ![]() Explanation In the above code, we have initialized the n variable to enter the number of rows for the pattern. We have initialized the value of n = 7, the range of outer for loop will be 0 to 4.
Inverted Right Triangle Star PatternAn Inverted right-angle triangle star pattern is exactly the opposite of the right-angle triangle pattern. In this pattern, the number of rows keeps decreasing subsequently with one star until a single star is left in the last row. Let’s see an example further to understand this pattern using a simple code snippet. ExampleCompile and RunOutput: ![]() Pyramid Star PatternA pyramid star pattern is formed by arranging stars in a triangular shape, where each row keeps on increasing while maintaining a pattern of an equal number of stars on the left and right of the centered star. The number of stars in a row is odd in number which makes the Pyramid star pattern possible. Let’s see an example to understand this pattern. ExampleCompile and RunOutput: ![]() Hollow PatternsHollow Patterns are the patterns that consists of the outer boundaries and the inner side is completely empty. Hollow Right-Angled Triangle PatternA Hollow Right-angled triangle pattern is formed by only printing the outer boundary of a right-angled triangle pattern with stars consisting of two perpendicular lines and one hypotenuse, and keeping the inside hollow. We must now see an example to understand the Hollow Right-Angled Triangle Pattern. ExampleCompile and RunOutput: ![]() Hollow Inverted Right-Angled Triangle PatternA Hollow Inverted Right-angled triangle pattern is formed by only printing the outer boundary of an inverted right-angled triangle pattern with stars consisting of two perpendicular lines and one hypotenuse, and keeping the inside hollow. Let’s see a simple example to understand the Hollow Inverted Right-Angled Triangle pattern. ExampleCompile and RunOutput: ![]() Simple Hollow Triangle PatternA Simple Hollow Triangle Pattern is formed by 2 tilted or slanted lines and a baseline joined together to form the shape of a Triangle while keeping the inner portion empty. Let’s see an example where we will learn how to print a simple hollow triangle pattern. ExampleCompile and RunOutput: ![]() Simple Hollow Inverted-Triangle PatternA Simple Hollow Inverted Triangle Pattern is formed by 2 tilted or slanted lines and a top line joined together to form the shape of a Triangle while keeping the inner portion empty. Let’s see an example where we will learn how to print a simple hollow inverted triangle pattern. ExampleCompile and RunOutput: ![]() Diamond Star PatternA Diamond Star Pattern is formed by two parts. In the first part, the number of stars increases toward the middle row, and in the second part, the numbers of stars decrease until a single star remains. It keeps proper spacing to maintain the diamond structure. Let’s see an example to learn how we can create a Diamond Star Pattern. ExampleCompile and RunOutput: ![]() Hollow Diamond PatternA hollow diamond pattern is formed by arranging stars along the boundary of a diamond shape, where the outer edges are printed with stars, while the inner area remains empty. Let’s see an example to print the Hollow Diamond Pattern. ExampleCompile and RunOutput: ![]() Hourglass Star PatternAn Hourglass star pattern is exactly the opposite of the diamond pattern. This pattern is formed by two parts, in the first part the number of stars decreases two the center, and in the second part it increases towards the center. Let’s see an example to print the Hourglass Star Pattern. ExampleCompile and RunOutput: ![]() Printing Number PatternsThe Number Patterns are created using the digits, where numbers are arranged in a specific order. Right-Angled Number Triangle PatternA right-angled number Triangle Pattern is a basic pattern printing concept that helps in logic building. It consists of integers that form a 90-degree right-angled triangle. Let’s see a simple example to learn how to print a Right-Angled Number Triangle Pattern. ExampleCompile and RunOutput: ![]() Inverted Right-Angled Number Triangle PatternAn inverted right-angled number triangle pattern is a basic pattern printing concept that helps in logic building. It consists of integers arranged in decreasing order to form a 90-degree right-angled triangle flipped upside down. Let’s see a simple example to learn how to print an Inverted Right-Angled Number Triangle Pattern. ExampleCompile and RunOutput: ![]() Number Pyramid PatternA number pyramid pattern is formed by arranging numbers in a triangular shape, where each row keeps on increasing while maintaining a pattern of an equal number of numbers on the left and right of the centered number. The number of elements in a row is odd in number which makes the number pyramid pattern possible. Below is the example where we will be printing the Number Pyramid Pattern. ExampleCompile and RunOutput: ![]() Inverted Number Pyramid PatternAn inverted number pyramid pattern is formed by arranging numbers in a triangular shape, where each row keeps on decreasing while maintaining a pattern of an equal number of numbers on the left and right of the centered number. The number of elements in a row is odd in number which makes the inverted number pyramid pattern possible. Below is the example where we will be printing the Inverted Number Pyramid Pattern. ExampleCompile and RunOutput: ![]() Floyd's Triangle PatternIn the Floyd's triangle pattern, every number will consist of the same number of elements. For example, 1st line will contain 1 element, the 2nd line will contain two elements, and all of these in increasing order. ExampleCompile and RunOutput: ![]() Explanation As we can see, every number of lines contains an equal number of elements. 1st line contains one, 2nd contains two, and so on. All of these elements are in increasing order, like 1 in the first line, 2 and 3 in the second line, etc. Pascal's Triangle PatternPascal’s Triangle Pattern is a number pattern in which each row represents the coefficients of a binomial expansion. The pattern starts with a single 1 at the top, and then every number is the sum of the two numbers directly above. This forms a triangle pattern known as Pascal’s Triangle. Now, we should see an example to learn how Pascal’s triangle is formed ExampleCompile and RunOutput: ![]() Spiral Number PatternA spiral number pattern is a pattern in which numbers are arranged in a spiral form. The numbers start in left-to-right order, and then after reaching a certain number, they go from right to left, forming a spiral pattern. Let’s see an example where we will build the Spiral Number Pattern. ExampleCompile and RunOutput: ![]() Zigzag Number PatternThe Zigzag pattern in Python is almost the same as Floyd's pattern, with the only difference being that every alternate line reverses the order, which symbolizes the zigzag pattern. Let’s see an example where we will build the Zigzag Number Pattern. ExampleCompile and RunOutput: ![]() Number Diamond PatternA Diamond Number Pattern is formed by two parts. In the first part, the number of numbers increases toward the middle row, and in the second part, the number of numbers decreases until a single number remains. It keeps proper spacing to maintain the diamond structure. Let’s see an example to learn how we can create a Diamond Number Pattern. ExampleCompile and RunOutput: ![]() Alphabet PatternAlphabet Right-Angled Triangle PatternAn alphabet right-angled triangle pattern is a basic pattern printing concept that helps in logic building. It consists of letters arranged to form a 90-degree right-angled triangle. Let’s see a simple example of learning how to print an alphabet right-angled triangle. ExampleCompile and RunOutput: ![]() Inverted Alphabet Right-Angled Triangle PatternAn inverted right-angle alphabet triangle pattern is exactly the opposite of the right-angle alphabet triangle pattern. In this pattern, the number of rows keeps decreasing subsequently with one alphabet until a single alphabet is left in the last row. Let’s see an example further to understand this pattern using a simple code snippet. ExampleCompile and RunOutput: ![]() Alphabet Pyramid PatternThe Alphabet Pyramid Pattern is formed by arranging the alphabet in a triangular order. It consists of one alphabet in the first line, and then the number of alphabets keeps on increasing, with the same alphabet on the left and right sides, while the alphabet in the middle keeps advancing with each line. Let’s see an example to understand the above Pattern: ExampleCompile and RunOutput: ![]() Inverted Alphabet Pyramid PatternThe Inverted Alphabet Pyramid Pattern is formed by arranging the alphabet in a triangular order. It starts with the maximum number of alphabets in the first line, and then the number of alphabets keeps on decreasing, with the same alphabet on the left and right sides, while the alphabet in the middle moves backward with each line. Let’s see an example to understand the above pattern: ExampleCompile and RunOutput: ![]() Alphabet Diamond PatternAn Alphabet Diamond Pattern is formed by two parts. In the first part, the number of alphabets increases toward the middle row, and in the second part, the number of alphabets decreases until a single alphabet remains. It keeps proper spacing to maintain the diamond structure. Let’s see an example to learn how we can create an Alphabet Diamond Pattern. ExampleCompile and RunOutput: ![]() ConclusionWe learnt about the various pattern programs in Python. It helps in building the concepts in the programming language. We studied Printing star patterns, Number patterns, Alphabet patterns, diamond patterns, Floyd's triangle, Pascal's triangle, Zigzag and hourglass patterns, etc. Next TopicPython built in module |
We request you to subscribe our newsletter for upcoming updates.