In Python, for loop, if loop, the input, and the print functions can be used to create patterns in python language. Pattern program in python using for loop uses these abstacts
- Outer loop which is used to print number of row.
- Inner loop which is used to print number of columns.
- Variables for printing whitespace as per requirement.
In this tutorial you are going to learn coding for star pattern program in python. Through this article you will learn various types of star patterns in python
- triangle pattern in python
- pyramid pattern in python
- number pattern in python
- alphabet pattern in python
- asterisk pattern in python and more
All you need to know is basics of Python Programming, even if you area beginner in python language you will be able to learn and code easily.
we are using Visual Studio 2012 for debugging purpose. But you can use any version of visual studio as per your availability.
Star Patterns in Python
Star pattern : 1
*
* *
* * *
* * * *
* * * * *
Star pattern : 2
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
k = 1
for i in range(0, 5):
for j in range(0, k):
print("* ", end="")
k = k + 2
print()
Star pattern : 3
k = 8
for i in range(0, 5):
for j in range(0, k):
print(end=" ")
k = k - 2
for j in range(0, i+1):
print("* ", end="")
print()
Star pattern : 4
k = 16
tim = 1
for i in range(0, 5):
for j in range(0, k):
print(end=" ")
k = k - 4
for j in range(0, tim):
print("* ", end="")
tim = tim + 2
print()
Star pattern 5
k = 0
rows = 5
for i in range(1, rows+1):
for space in range(1, (rows-i)+1):
print(end=" ")
while k != (2*i-1):
print("* ", end="")
k = k + 1
k = 0
print()
Star pattern 6
* * * * *
* * * *
* * *
* *
*
for i in range(0, 5):
for j in range(5, i, -1):
print("* ", end="")
print()
Star pattern 7
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
n=5;
for i in range(n):
for j in range(i):
print ('* ', end="")
print('')
for i in range(n,0,-1):
for j in range(i):
print('* ', end="")
print('')
Star pattern 8
n=5;
for i in range(0,n+1):
for j in range(0,n-i):
print(end=" ")
for j in range(0,i):
print("*",end=" ")
print()
if i==n:
for i in range(n-1,0,-1):
for j in range(0,n-i):
print(end=" ")
for j in range(0,i):
print("*",end=" ")
print()
Star pattern 9
for e in range (5,0,-1):
print((5-e) * ' ' + e * '*')
Star pattern 10
for g in range (6,0,-1):
print(g * ' ' + (6-g) * '*')
Star pattern 11
for row in range(1,5):
for col in range(1,8):
if (row==4 or row+col==5 or col-row==3):
print("*",end="")
else:
print(" ",end="")
print()
Star pattern 12
n=5;
for r in range(0,n):
for c in range(0,n):
if r==0 or c==(n-1) or r==c:
print("*",end="")
else:
print(end=" ")
print()
Star pattern 13 : ‘A’ Pattern in Python
result_str="";
for row in range(0,7):
for column in range(0,7):
if (((column == 1 or column == 5) and row != 0) or ((row == 0 or row == 3) and (column > 1 and column < 5))):
result_str=result_str+"*"
else:
result_str=result_str+" "
result_str=result_str+"\n"
print(result_str);
Star pattern 14 : ‘D’ Pattern in Python
result_str="";
for row in range(0,7):
for column in range(0,7):
if (column == 1 or ((row == 0 or row == 6) and (column > 1 and column < 5)) or (column == 5 and row != 0 and row != 6)):
result_str=result_str+"*"
else:
result_str=result_str+" "
result_str=result_str+"\n"
print(result_str);
Star pattern 15 : ‘E’ Pattern in Python
result_str="";
for row in range(0,7):
for column in range(0,7):
if (column == 1 or ((row == 0 or row == 6) and (column > 1 and column < 6)) or (row == 3 and column > 1 and column < 5)):
result_str=result_str+"*"
else:
result_str=result_str+" "
result_str=result_str+"\n"
print(result_str);
Star pattern 16 : ‘G’ Pattern in Python
result_str="";
for row in range(0,7):
for column in range(0,7):
if ((column == 1 and row != 0 and row != 6) or ((row == 0 or row == 6) and column > 1 and column < 5) or (row == 3 and column > 2 and column < 6) or (column == 5 and row != 0 and row != 2 and row != 6)):
result_str=result_str+"*"
else:
result_str=result_str+" "
result_str=result_str+"\n"
print(result_str);
Star pattern 17 : ‘L’ Pattern in Python
*
*
*
*
*
*
*****
result_str="";
for row in range(0,7):
for column in range(0,7):
if (column == 1 or (row == 6 and column != 0 and column < 6)):
result_str=result_str+"*"
else:
result_str=result_str+" "
result_str=result_str+"\n"
print(result_str);
Star pattern 18 : ‘M’ Pattern in Python

result_str="";
for row in range(0,7):
for column in range(0,7):
if (column == 1 or column == 5 or (row == 2 and (column == 2 or column == 4)) or (row == 3 and column == 3)):
result_str=result_str+"* "
else:
result_str=result_str+" "
result_str=result_str+"\n"
print(result_str);
Star pattern 19 : ‘O’ Pattern in Python
result_str="";
for row in range(0,7):
for column in range(0,7):
if (((column == 1 or column == 5) and row != 0 and row != 6) or ((row == 0 or row == 6) and column > 1 and column < 5)):
result_str=result_str+"*"
else:
result_str=result_str+" "
result_str=result_str+"\n"
print(result_str);
Star pattern 20 : ‘P’ Pattern in Python
result_str="";
for row in range(0,7):
for column in range(0,7):
if (column == 1 or ((row == 0 or row == 3) and column > 0 and column < 5) or ((column == 5 or column == 1) and (row == 1 or row == 2))):
result_str=result_str+"*"
else:
result_str=result_str+" "
result_str=result_str+"\n"
print(result_str);
Star pattern 21 : ‘X’ Pattern in Python
result_str="";
for row in range(0,7):
for column in range(0,7):
if (((column == 1 or column == 5) and (row > 4 or row < 2)) or row == column and column > 0 and column < 6 or (column == 2 and row == 4) or (column == 4 and row == 2)):
result_str=result_str+"*"
else:
result_str=result_str+" "
result_str=result_str+"\n"
print(result_str);
Star pattern 22 : ‘Z’ Pattern in Python
result_str="";
for row in range(0,7):
for column in range(0,7):
if (((row == 0 or row == 6) and column >= 0 and column <= 6) or row+column==6):
result_str=result_str+"*"
else:
result_str=result_str+" "
result_str=result_str+"\n"
print(result_str);