Alphabet Pattern Programs in Python
Last Updated :
03 May, 2025
Pattern programs help improve logic and problem-solving in coding. Using Python loops and the ASCII system, we can print alphabet-based patterns like triangles, pyramids and more.
ASCII Important Points:
- Uppercase letters: A-Z: ASCII 65–90
- Lowercase letters: a-z: ASCII 97–122
- Use chr() to convert an ASCII value to its character (e.g., chr(65)- 'A').
Let's look at some common alphabet patterns:
1. Left Triangle Alphabet Pattern
Prints a left-aligned triangle using uppercase letters. Each row prints increasing characters starting from 'A'.
Python
def left_triangle_pattern(rows):
for i in range(rows):
for j in range(i + 1):
print(chr(j + 65), end="")
print()
n = 7
left_triangle_pattern(n)
OutputA
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
Explanation:
- Outer loop controls rows.
- Inner loop prints increasing letters from 'A' in each row.
2. Right Triangle Alphabet Pattern in Python
Creates a right-aligned triangle by adding spaces before printing increasing characters from 'A'.
Python
def right_triangle_pattern(rows):
for i in range(rows):
for j in range(1, rows - i):
print(" ", end="")
for k in range(i + 1):
print(chr(65 + k), end="")
print()
n = 7
right_triangle_pattern(n)
Output A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
Explanation:
- Adds leading spaces to align right.
- Characters from 'A' to the required length are printed.
3. Hollow Triangle Alphabet Pattern in Python
In this example, we will build a left-aligned triangle with only the boundary letters visible, leaving the inner space blank.
Python
def hollow_left_triangle(rows):
for i in range(1, rows+1):
counter = 0
for j in range(i):
if j == 0 or j == i-1 or i == rows:
print(chr(65 + counter), end='')
counter += 1
else:
print(' ', end='')
print()
n = 7
hollow_left_triangle(n)
OutputA
AB
A B
A B
A B
A B
ABCDEFG
Explanation:
- Prints characters at the borders.
- Leaves spaces inside unless it's the last row.
4. Pyramid Alphabet Pattern in Python
Forms a centered pyramid where each row prints an odd number of letters starting from 'A'.
Python
def pyramid_pattern(rows):
for i in range(rows):
print(' ' * (rows - i - 1), end='')
for k in range(2 * i + 1):
print(chr(65 + k), end='')
print()
n = 7
pyramid_pattern(n)
Output A
ABC
ABCDE
ABCDEFG
ABCDEFGHI
ABCDEFGHIJK
ABCDEFGHIJKLM
Explanation:
- Each row is centered using spaces.
- Characters grow symmetrically from 'A'.
5. Upside Down Pyramid Alphabet Pattern in Python
Prints a reversed pyramid starting with the longest row and reducing characters each line.
Python
def reverse_pyramid(rows):
for i in range(rows):
print(' ' * i, end='')
for j in range(2 * (rows - i) - 1):
print(chr(65 + j), end='')
print()
n = 7
reverse_pyramid(n)
OutputABCDEFGHIJKLM
ABCDEFGHIJK
ABCDEFGHI
ABCDEFG
ABCDE
ABC
A
Explanation:
- Adds spaces to shift rows right.
- Characters reduce in odd numbers per row.
6. Hollow Pyramid Alphabet Pattern in Python
Creates a hollow pyramid by printing characters only on the border and full last row.
Python
def hollow_pyramid(rows):
for i in range(rows):
print(' ' * (rows - i - 1), end='')
counter = 0
for k in range(2 * i + 1):
if k == 0 or k == 2 * i or i == rows - 1:
print(chr(65 + counter), end='')
counter += 1
else:
print(' ', end='')
print()
n = 7
hollow_pyramid(n)
Output A
A B
A B
A B
A B
A B
ABCDEFGHIJKLM
Explanation:
- Borders of each row are filled.
- Middle spaces stay blank except in the last row.
7. Diamond Alphabet Pattern in Python
Combines an upright and reversed pyramid to form a symmetrical diamond of letters.
Python
def print_diamond(rows, is_upright=True):
if is_upright:
for i in range(rows):
print(' ' * (rows - i - 1), end='')
for j in range(2 * i + 1):
print(chr(65 + j), end='')
print()
else:
for i in range(rows - 1):
print(' ' * (i + 1), end='')
for j in range(2 * (rows - i - 1) - 1):
print(chr(65 + j), end='')
print()
n = 7
print_diamond(n, True)
print_diamond(n, False)
Output A
ABC
ABCDE
ABCDEFG
ABCDEFGHI
ABCDEFGHIJK
ABCDEFGHIJKLM
ABCDEFGHIJK
ABCDEFGHI
ABCDEFG
ABCDE
ABC
A
Explanation:
- First loop prints the upper triangle.
- Second loop prints the reversed lower part.
8. Hourglass Alphabet Pattern in Python
In this example, we will create an hourglass by stacking a reversed and upright pyramid pattern.
Python
def print_hourglass(rows):
for i in range(rows - 1):
print(' ' * i, end='')
for k in range(2 * (rows - i) - 1):
print(chr(65 + k), end='')
print()
for i in range(rows):
print(' ' * (rows - i - 1), end='')
for k in range(2 * i + 1):
print(chr(65 + k), end='')
print()
n = 7
print_hourglass(n)
OutputABCDEFGHIJKLM
ABCDEFGHIJK
ABCDEFGHI
ABCDEFG
ABCDE
ABC
A
ABC
ABCDE
ABCDEFG
ABCDEFGHI
ABCDEFGHIJK
ABCDEFGHIJKLM
Explanation:
- First half mirrors a reverse pyramid.
- Second half mirrors a pyramid.
9. Square Alphabet Pattern in Python
Prints a square where each row contains repeating uppercase letters in sequence.
Python
def print_square_pattern(rows):
for i in range(rows):
for j in range(rows):
print(chr(65 + i), end=" ")
print()
n = 7
print_square_pattern(n)
OutputA A A A A A A
B B B B B B B
C C C C C C C
D D D D D D D
E E E E E E E
F F F F F F F
G G G G G G G
Explanation:
- Each row contains the same alphabet.
- Characters increment with rows.
10. Heart Alphabet Pattern in Python
Draws a heart shape by combining mirrored patterns using uppercase alphabets.
Python
def print_heart_pattern(rows):
for i in range(rows // 2, rows, 2):
for j in range(1, rows - i, 2):
print(" ", end="")
for j in range(i):
print(chr(65 + j), end="")
for j in range(1, rows - i + 1):
print(" ", end="")
for j in range(i):
print(chr(65 + j), end="")
print()
for i in range(rows, 0, -1):
for j in range(i, rows):
print(" ", end="")
for j in range(i * 2):
print(chr(65 + j), end="")
print()
n = 10
print_heart_pattern(n)
Output:
ABCDE ABCDE
ABCDEFG ABCDEFG
ABCDEFGHI ABCDEFGHI
ABCDEFGHIJKLMNOPQRST
ABCDEFGHIJKLMNOPQR
ABCDEFGHIJKLMNOP
ABCDEFGHIJKLMN
ABCDEFGHIJKL
ABCDEFGHIJ
ABCDEFGH
ABCDEF
ABCD
AB
Explanation:
- Top part forms two arcs.
- Bottom descends forming a tapering shape.
11. Right Pascal Alphabet Pattern in Python
Forms a right Pascal triangle using alphabets with ascending and descending parts.
Python
def right_pascal_triangle(rows):
for i in range(1, rows + 1):
print(" " * (rows - i), end="")
for j in range(1, i + 1):
print(chr(64 + j), end="")
print()
for i in range(rows - 1, 0, -1):
print(" " * (rows - i), end="")
for j in range(1, i + 1):
print(chr(64 + j), end="")
print()
n = 7
right_pascal_triangle(n)
Output A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
ABCDEF
ABCDE
ABCD
ABC
AB
A
Explanation:
- First part grows rows.
- Second part reduces rows.
12. Left Pascal Alphabet Pattern in Python
Builds a left Pascal triangle with increasing and decreasing rows of characters.
Python
def left_pascal(rows):
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(chr(64 + j), end="")
print()
for i in range(rows - 1, 0, -1):
for j in range(1, i + 1):
print(chr(64 + j), end="")
print()
n = 7
left_pascal(n)
OutputA
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
ABCDEF
ABCDE
ABCD
ABC
AB
A
Explanation:
- Upper half increases from 1 to n.
- Lower half decreases from n-1 to 1.
Related Article: Programs for Printing Pyramid
Similar Reads
Python Program to Print Alphabetic Triangle Pattern
In this article, we examine a recursive method for printing character patterns in Python. Nesting loops are used in the conventional iterative approach to regulating character spacing and printing. We have provided the answer using both methods. This method prints an alphabet pattern in the form of
4 min read
Python List Creation Programs
Python provides multiple ways to create lists based on different requirements, such as generating lists of numbers, creating nested lists, forming lists of tuples or dictionaries, and more.This article covers various ways to create lists efficiently, including:Generating lists of numbers, strings, a
2 min read
Python Program to Sort Words in Alphabetical Order
The task is to write a program that takes a list of words as input and sorts them in alphabetical order. The program should display the sorted list of words, ensuring that the sorting is case-insensitive. To sort words in alphabetical order in Python, we can use the sorted() function or the sort() m
2 min read
Python List of List Programs
A list of lists is a common data structure in Python, used for handling multi-dimensional data, matrix operations and hierarchical data processing. Python provides several ways to manipulate and transform lists of lists, including sorting, merging, filtering and converting them into different format
2 min read
Print Alphabets till N-Python
Printing Alphabets till N in Python involves generating a sequence of uppercase or lowercase letters starting from 'A' (or 'a') up to the N-th letter of the alphabet. For example, if N = 5, the output should be: 'A B C D E'. Let's explore a few ways to implement this in a clean and Pythonic way.Usin
2 min read
Output of Python programs | Set 8
Prerequisite - Lists in Python Predict the output of the following Python programs. Program 1 Python list = [1, 2, 3, None, (1, 2, 3, 4, 5), ['Geeks', 'for', 'Geeks']] print len(list) Output: 6Explanation: The beauty of python list datatype is that within a list, a programmer can nest another list,
3 min read
Output of Python programs | Set 7
Prerequisite - Strings in Python Predict the output of the following Python programs. These question set will make you conversant with String Concepts in Python programming language. Program 1Python var1 = 'Hello Geeks!' var2 = "GeeksforGeeks" print "var1[0]: ", var1[0] # statement 1 print "var2[1:5
3 min read
Python Coding Practice Problems
This collection of Python coding practice problems is designed to help you improve your overall programming skills in Python.The links below lead to different topic pages, each containing coding problems, and this page also includes links to quizzes. You need to log in first to write your code. Your
1 min read
Output of Python Programs | Set 22 (Loops)
Prerequisite: LoopsNote: Output of all these programs is tested on Python3 1. What is the output of the following?Python mylist = ['geeks', 'forgeeks'] for i in mylist: i.upper() print(mylist) [âGEEKSâ, âFORGEEKSâ].[âgeeksâ, âforgeeksâ].[None, None].Unexpected Output: 2. [âgeeksâ, âforgeeksâ]Explana
2 min read
Python Programs
Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co
11 min read