dev.rean.me
python

13 Examples: Print Patterns with Loops in Python (Video in Khmer)

Learn to print square and triangle patterns with Python loops. Simple examples and tips for beginners.

2026-10-22 ยท 3 min read

Share:

Hello friend! ๐Ÿ‘‹ A loop can print a pattern many time. We use one loop for rows and another loop for items in each row.

In this post, I show you easy star patterns with Python loops. ๐Ÿ


๐ŸŽฅ Video: Square Pattern in Python (Khmer)


โญ Square Pattern

Print 4 rows. Each row has 4 stars.

for row in range(4):
    for col in range(4):
        print("*", end=" ")
    print()

Output:

* * * *
* * * *
* * * *
* * * *

The inside loop print stars. The last print() move to a new line.


๐Ÿ”บ Left Triangle Pattern

Each row has one more star than the row before.

for row in range(1, 5):
    for col in range(row):
        print("*", end=" ")
    print()

Output:

*
* *
* * *
* * * *

๐ŸŽฅ Video: Print Left Triangle Star Pattern Using Loop (Khmer)


๐Ÿ”ป Down Left Triangle Pattern

Each row has one less star.

for row in range(4, 0, -1):
    for col in range(row):
        print("*", end=" ")
    print()

Output:

* * * *
* * *
* *
*

๐ŸŽฅ Video: Print Down Left Triangle Star Pattern Using Loop (Khmer)


๐Ÿ”ข Number Pattern

Print the row number as the pattern.

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

Output:

1
2 2
3 3 3
4 4 4 4

๐Ÿ’ก Tips

  • The outside loop make each row.
  • The inside loop print items in a row.
  • Use print("*", end=" ") to keep items on one line.
  • Use print() to start a new line after each row.
  • Change range(4) to make more or less rows.
  • Check your spaces and indentation. Code inside a loop need indentation.

โ“ Any Question?

Tell us in comment below! ๐Ÿ‘‡

#Python #Loop #Pattern #ForLoop #LearnPython #Beginner


๐Ÿ“š Related Post

โ† Back to python
Share: