Hollow Diamond Star Pattern in Python

Beginner
⏱️ 9 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
2n − 1 rows total

What You'll Learn

This pattern is Program 7 (inverted V, upper half) plus the lower half using the same outer idea as Program 8: after i runs 1rows, run i from rows - 1 down to 1 with the same hollow-gap logic.

Each printed line has width 2 * rows - 1 (9 characters when rows = 5).

⭐ Pattern Output

When you run the program with rows = 5:

Output
    *
   * *
  *   *
 *     *
*       *
 *     *
  *   *
   * *
    *
1

Complete Python Program

Fixed rows = 5 version:

Python
rows = 5

# Upper half (same idea as Program 7)
for i in range(1, rows + 1):
    print(" " * (rows - i), end="")
    print("*", end="")

    if i > 1:
        print(" " * (2 * i - 3), end="")
        print("*", end="")

    print()

# Lower half (same idea as Program 8), start from rows - 1 to avoid duplicate middle row
for i in range(rows - 1, 0, -1):
    print(" " * (rows - i), end="")
    print("*", end="")

    if i > 1:
        print(" " * (2 * i - 3), end="")
        print("*", end="")

    print()

🧠 How It Works

1

Upper half (i = 1rows)

for i in range(1, rows + 1): repeats Program 7’s body: margin string, first *, optional " " * (2 * i - 3) and second *, then print(). The waist row (i == rows) is the widest.

Expanding
2

Lower half (i = rows - 11)

for i in range(rows - 1, 0, -1): runs the same row logic as the upper half so the shape narrows again. Starting at rows - 1 skips duplicating the widest row.

Mirrored
3

Per-row pieces

Every row uses print(" " * (rows - i), end=""), print("*", end=""), and when i > 1 the gap plus second star—all without newlines until the final print() on that row.

Edges
4

Width

Each printed line has 2 * rows - 1 characters. Total lines: rows + (rows - 1) = 2 * rows - 1.

Line break
=

Full hollow diamond

O(n²) output for n = rows, O(1) extra space. Width 2n - 1 scrolls horizontally in the green preview on narrow screens.

2

Variation — User Input Version

Read rows from user input:

Python
rows = int(input("Enter the number of rows: "))

for i in range(1, rows + 1):
    print(" " * (rows - i), end="")
    print("*", end="")
    if i > 1:
        print(" " * (2 * i - 3), end="")
        print("*", end="")
    print()

for i in range(rows - 1, 0, -1):
    print(" " * (rows - i), end="")
    print("*", end="")
    if i > 1:
        print(" " * (2 * i - 3), end="")
        print("*", end="")
    print()

💡 Tips for Enhancement

Try These

  • Print a filled diamond by using Program 5 + Program 6 logic (Program 10)
  • Change the character from * to # or @
  • Use string-building to create each line and print once per row
  • Validate rows > 0 before printing
  • Try adding a frame around the diamond (Program 11)

Avoid

  • Starting the lower half at rows (middle row duplicates)
  • Mixing tabs and spaces (alignment breaks)
  • Forgetting newline between rows
  • Printing the second star when i == 1
  • Assuming user input is always valid

Key Takeaways

1

The diamond is built by printing the upper half then mirroring it as the lower half.

2

Each row is 2 * rows - 1 characters wide.

3

Lower half starts at rows - 1 to avoid duplicating the middle row.

4

Time complexity is O(n²) for n rows.

5

This diamond uses the same edge logic as Programs 7 and 8.

❓ Frequently Asked Questions

Because the upper half already prints the widest row. Starting from rows - 1 prevents printing the middle row twice.
Instead of printing only the two boundary stars, print stars for all positions between them (Program 10).
It’s O(n²) because each row prints Theta(n) characters across Theta(n) rows.

Next: Filled Diamond Pattern

Continue to Program 10 to print a filled diamond star pattern in Python.

Program 10 →
Did you know?

The hollow diamond is a classic pattern exercise because it combines symmetry, loops, and careful boundary printing.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful