Pattern Program in Python

Last 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.

Pattern Program in Python

We have classified the Python pattern program into three categories:

  • Start Pattern
  • Number Pattern
  • Character Pattern

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.

  • The outer loop to print the number of rows.
  • The inner loops to print the number of columns.
  • The variable to print whitespace according to the required place in Python.
Pattern Program in Python

Printing Star Patterns

Right Triangle Star Pattern

A 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

Example

Compile and Run

Output:

Pattern Program in Python

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.

  • The iteration of the inner for loop depends on the outer loop. The inner loop is responsible to print the number of columns.
  • In the first iteration, the value of i is 0, and it increased by 1, so it becomes 0+1, now inner loop iterated first time and print one star(*).
  • In the second iteration, the value of i is 1 and it increased by 1, so it becomes 1+1, now inner loop iterated two times and print two-star (*).
  • The end argument prevents to jump into another line. It will printer the star until the loop is valid.
  • The last print statement is responsible for ending the line after each row.

Inverted Right Triangle Star Pattern

An 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.

Example

Compile and Run

Output:

Pattern Program in Python

Pyramid Star Pattern

A 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.

Example

Compile and Run

Output:

Pattern Program in Python

Hollow Patterns

Hollow Patterns are the patterns that consists of the outer boundaries and the inner side is completely empty.

Hollow Right-Angled Triangle Pattern

A 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.

Example

Compile and Run

Output:

Pattern Program in Python

Hollow Inverted Right-Angled Triangle Pattern

A 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.

Example

Compile and Run

Output:

Pattern Program in Python

Simple Hollow Triangle Pattern

A 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.

Example

Compile and Run

Output:

Pattern Program in Python

Simple Hollow Inverted-Triangle Pattern

A 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.

Example

Compile and Run

Output:

Pattern Program in Python

Diamond Star Pattern

A 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.

Example

Compile and Run

Output:

Pattern Program in Python

Hollow Diamond Pattern

A 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.

Example

Compile and Run

Output:

Pattern Program in Python

Hourglass Star Pattern

An 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.

Example

Compile and Run

Output:

Pattern Program in Python

Printing Number Patterns

The Number Patterns are created using the digits, where numbers are arranged in a specific order.

Right-Angled Number Triangle Pattern

A 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.

Example

Compile and Run

Output:

Pattern Program in Python

Inverted Right-Angled Number Triangle Pattern

An 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.

Example

Compile and Run

Output:

Pattern Program in Python

Number Pyramid Pattern

A 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.

Example

Compile and Run

Output:

Pattern Program in Python

Inverted Number Pyramid Pattern

An 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.

Example

Compile and Run

Output:

Pattern Program in Python

Floyd's Triangle Pattern

In 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.

Example

Compile and Run

Output:

Pattern Program in Python

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 Pattern

Pascal’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

Example

Compile and Run

Output:

Pattern Program in Python

Spiral Number Pattern

A 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.

Example

Compile and Run

Output:

Pattern Program in Python

Zigzag Number Pattern

The 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.

Example

Compile and Run

Output:

Pattern Program in Python

Number Diamond Pattern

A 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.

Example

Compile and Run

Output:

Pattern Program in Python

Alphabet Pattern

Alphabet Right-Angled Triangle Pattern

An 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.

Example

Compile and Run

Output:

Pattern Program in Python

Inverted Alphabet Right-Angled Triangle Pattern

An 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.

Example

Compile and Run

Output:

Pattern Program in Python

Alphabet Pyramid Pattern

The 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:

Example

Compile and Run

Output:

Pattern Program in Python

Inverted Alphabet Pyramid Pattern

The 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:

Example

Compile and Run

Output:

Pattern Program in Python

Alphabet Diamond Pattern

An 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.

Example

Compile and Run

Output:

Pattern Program in Python

Conclusion

We 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.