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
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