Pyramid Pattern in Python

Hello everyone, welcome back to! I recently started a new series on pattern programming, I explained how to print a  Floyd’s Triangle pattern in the previous post. Here I will explain to you how to print a pyramid pattern or a triangle pattern in Python.

Program on Github

You can also watch the video on YouTube here.

Pyramid Pattern – Code Visualization


Python Program to print a Pyramid/Triangle Pattern.


  • Read an input integer for asking the range of the triangle using  input()
  • Run 3 for loops, one main for column looping and other 2 sub-loops for row looping, in the first loop, loop through the range of the triangle for column looping.
  • In the second loop, loop through the value of the range – 1, this is to print space
  • In the third loop, loop through the value of i+1 and print *

Program on Github



Triangle Pattern -
Pyramid Pattern –

Program on Github

That is it for this tutorial. Also feel free to look at programs on other patterns or some algorithms implementation in python here or look at all of the posts here.

Course Suggestion

Machine Learning everywhere! So I strongly suggest you to take the course below.
Course: Machine Learning Adv: Support Vector Machines (SVM) Python



  1. Sailee Mukherjee

    hi I did the same thing but I am getting different type of pattern

    num=int(input(“enter the number: “))
    for i in range(num):
    for j in range((num-i)-1):
    for j in range(0,i+1):




Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.