When I started learning Python, one of the first challenges I faced was printing patterns. At that time, I didn’t realize how useful these small exercises were in building problem-solving skills. It looks simple, but it teaches you how to work with loops, conditions, and spacing in Python.
In this tutorial, I’ll show you exactly how to print a diamond pattern in Python. I’ll share multiple methods I’ve personally used, explain the logic step by step, and give you complete code examples.
By the end, you’ll be able to create your variations of the diamond pattern and understand how loops can be used to solve real-world problems.
What is a Diamond Pattern?
A diamond pattern is a symmetrical shape made of stars (*). It looks like this:
*
***
*****
*******
*********
*******
*****
***
*The idea is simple:
- The top half is an increasing triangle.
- The bottom half is a decreasing triangle.
Once you understand this, printing the diamond becomes much easier.
Method 1 – Print Diamond Pattern Using a For Loop
This is the most common way to print a diamond pattern in Python.
Here’s the step-by-step process I follow:
- Decide the number of rows for the top half.
- Use a
forloop to print spaces and stars for each row. - Repeat the process in reverse for the bottom half.
Example Code:
# Diamond pattern using for loop
rows = 5 # You can change this value
# Top half of the diamond
for i in range(rows):
print(" " * (rows - i - 1) + "*" * (2 * i + 1))
# Bottom half of the diamond
for i in range(rows - 2, -1, -1):
print(" " * (rows - i - 1) + "*" * (2 * i + 1))Output:
*
***
*****
*******
*****
***
*You can refer to the screenshot below to see the output.

This method is simple and works perfectly for small to medium-sized diamonds.
Method 2 – Diamond Pattern Using a While Loop
Sometimes I prefer using a while loop because it gives me more control over the loop variable.
Example Code:
# Diamond pattern using while loop
rows = 5
i = 0
# Top half
while i < rows:
print(" " * (rows - i - 1) + "*" * (2 * i + 1))
i += 1
# Bottom half
i = rows - 2
while i >= 0:
print(" " * (rows - i - 1) + "*" * (2 * i + 1))
i -= 1You can refer to the screenshot below to see the output.

The output is the same, but this approach is useful if you’re practicing while loops.
Method 3 – Diamond Pattern with User Input
In real projects, I often allow users to decide the size of the pattern. This makes the program more flexible.
Example Code:
# Diamond pattern with user input
rows = int(input("Enter the number of rows: "))
# Top half
for i in range(rows):
print(" " * (rows - i - 1) + "*" * (2 * i + 1))
# Bottom half
for i in range(rows - 2, -1, -1):
print(" " * (rows - i - 1) + "*" * (2 * i + 1))You can refer to the screenshot below to see the output.

If the user enters 7, the diamond will be taller and wider.
Method 4 – Diamond Pattern Using Functions
As an experienced developer, I always recommend writing reusable code. Wrapping the logic in a function makes it easy to call multiple times.
Example Code:
def print_diamond(rows):
# Top half
for i in range(rows):
print(" " * (rows - i - 1) + "*" * (2 * i + 1))
# Bottom half
for i in range(rows - 2, -1, -1):
print(" " * (rows - i - 1) + "*" * (2 * i + 1))
# Example usage
print_diamond(5)
print("\nAnother diamond:\n")
print_diamond(7)Now you can print diamonds of different sizes just by calling the function.
Real-Life Example – Why Learn Pattern Printing?
You may wonder, “Why should I learn to print a diamond pattern?”
When I interview junior developers in the USA, I often ask them simple pattern problems. It’s not because I need diamonds in my projects, but because these problems show how well someone understands loops, conditions, and logic building.
If you can solve a diamond pattern, you’ll find it easier to solve data formatting problems, build console-based UIs, or even generate structured reports.
Conclusion
- Printing a diamond pattern is a great way to practice loops in Python.
- You can use
forloops,whileloops, or even functions, to make your code reusable. - Allowing user input makes your program more flexible.
- These exercises build the foundation for solving real-world coding challenges.
I hope you found this tutorial helpful. If you try the code examples, you’ll quickly get comfortable with loops and conditions in Python.
You may like to read:
- Use Static Variables in Python Functions
- Difference Between Class and Instance Variables in Python
- Insert a Python Variable into a String
- Write a Variable to a File in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.