Python Number Pattern Programs

Beginner
6 min read
Updated: Nov 2026
3 examples
print + end=""

Definition and Usage

A Python number pattern is a script that prints integers in rows. The outer for loop chooses the row. The inner loop prints each number with end="", then a bare print() ends that row.

print(n) adds a newline, so a digit printed that way lands on its own line. print(10, end=""); print(11, end="") stays on one row and prints 1011. print(10, 11) inserts a space, because sep defaults to " ". 10 + 11 is addition, so that expression prints 21.

range stops before the end value.

range(rows, 0, -1) counts down through rows and stops before 0, so the last row is 1. range(1, row + 1) includes row.

Python Syntax

Count the outer loop down when the first row should be the longest. The inner loop still walks 1 through the current width.

Python
for row in range(rows, 0, -1):
    for n in range(1, row + 1):
        print(n, end="")   # digits, no space
    print()                # end the row

How Python Prints a Number

Map each part of the console shape to a Python value or call.

PiecePythonWhat it does
Digitprint(n, end="")Writes the number and stays on the row
Same digitprint(row, end="")Repeats the row number on that line
Next valuevalue += 1Keeps counting across columns and rows
Gluestr(10) + str(11)The string "1011"
Add10 + 11The number 21
New rowprint()Ends the row
Widthf"{n:2d}"Two columns, padded on the left
Odd or evenn % 20/1 patterns from the remainder
One digitchr(ord('0') + n)One character for 0–9

Python Examples

Three scripts. Each one changes only the Python that chooses the number or its width.

Example 1 — Shrink the row with range

The step -1 counts down. The inner loop still starts at 1 and stops after row.

Python
rows = 5

for row in range(rows, 0, -1):
    for n in range(1, row + 1):
        print(n, end="")
    print()

How It Works

  1. range(rows, 0, -1) yields 5, 4, 3, 2, 1. It never yields 0.
  2. The inner range always restarts at 1, so every row begins with 1.
  3. end="" keeps the digits together. print() starts the next row.

Example 2 — Print the row number, not the column

The inner loop only decides how many times to print. The value is row.

Python
rows = 5

for row in range(1, rows + 1):
    for col in range(row):
        print(row, end="")
    print()

How It Works

  1. range(row) runs once on row 1 and three times on row 3.
  2. Each pass prints row, so row 3 becomes 333.
  3. Swap print(row, end="") for print(col + 1, end="") and the line becomes 123.

Example 3 — Keep two-digit values aligned

f"{value:2d}" reserves two columns. " ".join puts one space between those fields.

Python
value = 1

for row in range(1, 5):
    parts = []
    for col in range(row):
        parts.append(f"{value:2d}")
        value += 1
    print(" ".join(parts))

How It Works

  1. value lives outside both loops, so counting continues on the next row.
  2. :2d turns 1 into " 1" and leaves 10 as two digits.
  3. The join space is separate from that width. print writes the finished row.

62 Python Number Pattern Programs

Each card is a full Python script: nested for loops, a number for the cell, and print(..., end=""). Open one for the walkthrough.

Number Pattern 1
Number Pattern 2
Number Pattern 3
Number Pattern 4
Number Pattern 5
Number Pattern 6
Number Pattern 7
Number Pattern 8
Number Pattern 9
Number Pattern 10
Number Pattern 11
Number Pattern 12
Number Pattern 13
Number Pattern 14
Number Pattern 15
Number Pattern 16
Number Pattern 17
Number Pattern 18
Number Pattern 19
Number Pattern 20
Number Pattern 21
Number Pattern 22
Number Pattern 23
Number Pattern 24
Number Pattern 25
Number Pattern 26
Number Pattern 27
Number Pattern 28
Number Pattern 29
Number Pattern 30
Number Pattern 31
Number Pattern 32
Number Pattern 33
Number Pattern 34
Number Pattern 35
Number Pattern 36
Number Pattern 37
Number Pattern 38
Number Pattern 39
Number Pattern 40
Number Pattern 41
Number Pattern 42
Number Pattern 43
Number Pattern 44
Number Pattern 45
Number Pattern 46
Number Pattern 47
Number Pattern 48
Number Pattern 49
Number Pattern 50
Number Pattern 51
Number Pattern 52
Number Pattern 53
Number Pattern 54
Number Pattern 55
Number Pattern 56
Number Pattern 57
Number Pattern 58
Number Pattern 59
Number Pattern 60
Number Pattern 61
Number Pattern 62

Frequently Asked Questions

print(10, end=""); print(11, end="") writes the digits with no separator, so the row is 1011. str(10) + str(11) is the same string. print(10, 11) inserts a space because sep defaults to " ". Addition is different: 10 + 11 is 21.
print(n) writes the number and ends the row. print(n, end="") stays on the same row. A bare print() after the inner loop ends the row. If the default print sits inside the inner loop, each digit lands on its own line.
f"{n:2d}" reserves two columns for that value. It only affects that number. " ".join separates the columns. str(n).rjust(2) pads the string form the same way.
Yes, when the value is 0 through 9. chr(ord('0') + n) is one character. print(n, end="") still works, and it is the call you need once the value reaches 10.

Next: Number Pattern 1

A full Python walkthrough of the descending number triangle, from range(rows, 0, -1) through print().

Number Pattern 1 →

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.

28 people found this page helpful