Alphabet Pattern (A to ABCDE) in Python

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
n(n+1)/2 letters total

What You'll Learn

This Python program prints an alphabet pattern where each row starts at A and grows by one letter.

For n rows, the total letters printed are 1 + 2 + … + n = n(n + 1)/2.

⭐ Pattern Output

When you run the program with rows = 5:

Output
A
AB
ABC
ABCD
ABCDE
1

Complete Python Program

Fixed rows = 5 version (no magic ASCII numbers):

Python
rows = 5

start = ord('A')

for i in range(1, rows + 1):
    for code in range(start, start + i):
        print(chr(code), end="")
    print()

🧠 How It Works

1

Outer loop: one row per i

for i in range(1, rows + 1) runs once per row. Row i prints exactly i letters.

Outer
2

Letter codes with ord() / chr()

start = ord('A') converts A into a number. The inner loop walks from start to start + i - 1, and chr(code) converts each number back to a letter.

Inner
3

Finish the row

print(chr(code), end="") appends letters on the same line, and the final print() adds a newline so the next row starts on a fresh line.

print
=

Growing alphabet rows

Total prints are 1+2+…+n = n(n + 1)/2, so runtime is O(n²) and extra space is O(1).

2

Variation — User Input Version

Read rows from user input (clamped to 26 to stay within A–Z):

Python
rows = int(input("Enter the number of rows (max 26): "))
rows = max(1, min(rows, 26))

start = ord('A')

for i in range(1, rows + 1):
    for code in range(start, start + i):
        print(chr(code), end="")
    print()

💡 Tips for Enhancement

Try These

  • Start from a different letter (e.g., 'C')
  • Print lowercase output by using ord('a')
  • Add spaces between letters (e.g., print with end=" ")
  • Try a centered alphabet pyramid next

Avoid

  • Using magic numbers like 65 when ord('A') is clearer
  • Allowing rows > 26 without handling wrap-around
  • Forgetting a newline after each row
  • Mixing tabs/spaces inconsistently in Python examples

Key Takeaways

1

Use nested loops: outer for rows, inner for letters.

2

Row i prints letters from A to the i-th letter.

3

Total printed letters are \(n(n+1)/2\), so runtime is O(n²).

4

Prefer ord()/chr() over raw ASCII numbers.

5

Clamp user input to 26 rows to stay within A to Z.

❓ Frequently Asked Questions

Yes. Change ord('A') to ord('a') (and keep the 26-row cap).
Use print(chr(code), end=" ") inside the inner loop, then print a newline after the row.
It’s O(n²) for n rows, because the program prints 1+2+…+n letters in total.

Next: Python Alphabet Pattern 2

Continue to Program 2 for the next alphabet pattern in Python.

Program 2 →
Did you know?

In Python, ord() and chr() are the go-to tools for converting between letters and numeric codes while generating patterns.

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.

10 people found this page helpful