Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

Top Python Programs to Create Pattern

Updated on 06 October, 2022

6.38K+ views
8 min read

Python is currently the top most popular programming language globally after having dethroned C on TIOBE Index. Given its easy readability and simple syntax, which is similar to English Language, Python is extensively used on different platforms like Windows, Mac, Linux, Raspberry Pi, etc. 

Part of the huge demand for Python is that it has an easy learning curve due to its close to human language nature. Also, writing Python programs takes a fraction of the time compared to other programming languages, thereby speeding up the development process. 

Using Python, developers can develop efficient applications quickly, whether it is a complex machine learning program or simple pattern-creating codes.

In this article, we will list out some top programs to create star patterns using Python.

Why should you learn how to create patterns? 

Python finds extensive use in task automation, data analysis, machine learning, and artificial intelligence, where a huge part of programming involves identifying and creating patterns to make accurate predictions. This allows developers to recognize relationships in data and build generalizations to solve complex mathematical problems. 

Luckily Python design patterns codes are very easy to create and implement and offer the ability to create and print a wide variety of patterns. 

Star Patterns are among the most common patterns in most programming languages. It consists of a series of stars, and for printing star patterns, you only need to have a basic understanding of Python programming concepts like the use of ‘for loop’, ‘if loop’, and input and print functions. 

A basic pattern matching Python program primarily consists of two ‘for’ loops, where the outer loop is for rows, and the inner loop is for columns in the pattern. We have the print function to print the output and the input function to receive the user input. 

Let’s now look at the various types of star pattern Python programs below:

Square Pattern

The square pattern is one of the easiest patterns to create in Python. The idea is to print stars or characters in the form of a square. Two nested loops are used to print a square pattern; the internal for loop prints stars (*) and creates a new line after every row, the outer loop creates the rows, and the inner loop creates columns.

Code:

for i in range(0, 5):

    for j in range(0, 5):

        print(“*”, end=””)

    print()

Output:

*****

*****

*****

*****

*****

Right Angle Triangle Pyramid Pattern

It is to print the required number or character (in this case, stars) in the shape of a right-angle triangle pyramid.

Code:

l = 5

for i in range(0, l):

    # nested loop for each column

    for j in range(0, i + 1):

        # print star

        print(“*”, end=’ ‘)

    # new line after each row

    print(“\r”)

Output:

* * 

* * * 

* * * * 

* * * * * 

Mirrored Right Triangle

It is a star pattern in an inverted right triangle pyramid, also known as a mirrored right triangle.

Code:

# number of rows

rows = 5

k = 2 * rows – 2

for i in range(0, rows):

    # process each column

    for j in range(0, k):

        # print space in pyramid

        print(end=” “)

    k = k – 2

    for j in range(0, i + 1):

        # display star

        print(“* “, end=””)

    print(“”)

Output:

        * 

      * * 

    * * * 

  * * * * 

* * * * * 

Downward half-Pyramid Star Pattern

We use the reverse nested for loop to print the downward pyramid pattern of stars.

Code:

rows = 5

for i in range(rows + 1, 0, -1):

    # nested reverse loop

    for j in range(0, i – 1):

        # display star

        print(“*”, end=’ ‘)

    print(” “)

Output:

* * * * *  

* * * *  

* * *  

* *  

*

Equilateral Triangle or Pyramid Star Pattern Python

This star pattern will be in the form of an equilateral triangle.

Code:

n = 5

for i in range(n):

    for j in range(n – i – 1):

        print(‘ ‘, end=”)

    for k in range(2 * i + 1):

        print(‘*’, end=”)

    print()

Output:

    *

   ***

  *****

 *******

*********

Reverse Pyramid Pattern

Next, we will print the pyramid pattern in reverse.

Code:

rows = 5

k = 2 * rows – 2

for i in range(rows, -1, -1):

    for j in range(k, 0, -1):

        print(end=” “)

    k = k + 1

    for j in range(0, i + 1):

        print(“*”, end=” “)

    print(“”)

Output:

        * * * * * * 

         * * * * * 

          * * * * 

           * * * 

            * * 

             * 

Diamond-Shaped Star Pattern

This star pattern is in the shape of a diamond. We use the nested loops again. The program is a combination of pyramid and reverse-pyramid patterns.

Code:

rows = 5

k = 2 * rows – 2

for i in range(0, rows):

    for j in range(0, k):

        print(end=” “)

    k = k – 1

    for j in range(0, i + 1):

        print(“* “, end=””)

    print(“”) 

k = rows – 2

for i in range(rows, -1, -1):

    for j in range(k, 0, -1):

        print(end=” “)

    k = k + 1

    for j in range(0, i + 1):

        print(“* “, end=””)

    print(“”)

Output:

        * 

       * * 

      * * * 

     * * * * 

    * * * * * 

   * * * * * * 

    * * * * * 

     * * * * 

      * * * 

       * * 

        * 

Hollow Diamond Pattern

The hollow diamond star pattern is the same as the diamond star pattern, but it is hollow. This pattern Python program is a little complex as we need to deal with multiple points. The pattern is divided into two parts – the upper pyramid and the lower pyramid.

Code:

rows = 5

i = 1

while i <= rows:

    j = rows

    while j > i:

        # display space

        print(‘ ‘, end=’ ‘)

        j -= 1

    print(‘*’, end=’ ‘)

    k = 1

    while k < 2 * (i – 1):

        print(‘ ‘, end=’ ‘)

        k += 1

    if i == 1:

        print()

    else:

        print(‘*’)

    i += 1

i = rows – 1

while i >= 1:

    j = rows

    while j > i:

        print(‘ ‘, end=’ ‘)

        j -= 1

    print(‘*’, end=’ ‘)

    k = 1

    while k <= 2 * (i – 1):

        print(‘ ‘, end=’ ‘)

        k += 1

    if i == 1:

        print()

    else:

        print(‘*’)

    i -= 1

Output:

    *

   * *

  * *

 * *

* *

 * *

  * *

   * *

    *

Sand Glass Star Pattern

The hourglass or sandglass pattern is a pattern shaped like an hourglass. As you observe the pattern, you will see that the pattern is made up of a downward pyramid pattern and an upward triangle pattern.

Code:

n = 5

# downward pyramid

for i in range(n-1):

    for j in range(i):

        print(‘ ‘, end=”)

    for k in range(2*(n-i)-1):

        print(‘*’, end=”)

    print()

# upward pyramid

for i in range(n):

    for j in range(n-i-1):

        print(‘ ‘, end=”)

    for k in range(2*i+1):

        print(‘*’, end=”)

    print()

Output:

*********

 *******

  *****

   ***

    *

   ***

  *****

 *******

*********

Right Pascal Triangle Star Pattern

The Right Pascal Triangle Star pattern, consists of an upper triangle and a lower triangle.

Code:

rows = 5

for i in range(0, rows):

    for j in range(0, i + 1):

        print(“*”, end=’ ‘)

    print(“\r”)

for i in range(rows, 0, -1):

    for j in range(0, i – 1):

        print(“*”, end=’ ‘)

    print(“\r”)

Output:

* * 

* * * 

* * * * 

* * * * * 

* * * * 

* * * 

* * 

Left Pascal Triangle Star Pattern

This pattern is a mirror image of the right pascal triangle pattern. Compared to the right pascal triangle pattern, the left pascal triangle is a little bit complicated as you need to deal with both spaces and stars.

Code:

n = 5

# upper triangle

for i in range(n):

    # print spaces

    for j in range(n – i – 1):

        print(‘ ‘, end=”)

    # print stars

    for k in range(i + 1):

        print(‘*’, end=”)

    print()

# lower triangle

for i in range(n – 1):

    # print spaces

    for j in range(i + 1):

        print(‘ ‘, end=”)

    # print stars

    for k in range(n – i – 1):

        print(‘*’, end=”)

    print()

Output:

        * 

      * * 

    * * * 

  * * * * 

* * * * * 

  * * * * 

    * * * 

      * * 

        * 

Those were some top Python programs to create star patterns. Many other star pattern programs are equally easy to create using Python, whether alphabets or numbers.

Since Python developers can write efficient programs using just a few lines, enhancing the language’s appeal and usage.

As per the research and analysis conducted in 2019 under the ‘Technical Skills With Huge Demand’ by Forbes, Python ranked seventh, having registered a 456% growth rate. In 2021, the monthly TIOBE Index of language popularity declared that Python had secured the top position, having left C and Java behind; the languages secured the second and third positions, respectively, in November 2021. 

Being skilled at Python in the current competitive market can give you the much-needed edge to progress in your career. If you’d like to master Python and foray into the field of Data Science, we recommend joining upGrad’s Advanced Certificate Program in Data Science offered by IIIT Bangalore. The 8-month program has industry experts from top companies like Flipkart, Walmart, and Gramener to help you build essential hard and soft skills to succeed as a data science professional.

The program also includes a complimentary Python programming Bootcamp, 7+ case studies and projects, and access to Kaggle competitions to help students build hands-on experience in the field. 

An advanced certificate program can increase your chances of success in data science. So, go ahead and book your seat in the program today!

Learn data science courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

Frequently Asked Questions (FAQs)

1. How do pattern programs in Python work?

Every pattern program in Python employs at least two for loops, one denoting the number of rows, and the other, denoting columns. The number of loops that will be used depends on the complexity of the pattern program.

2. What are pattern programs?

Pattern programs are codes written to print numbers, alphabets, or special characters in your desired form, be it as a triangle, pyramid, inverted triangle, diamond, etc.

3. What are some commonly asked pattern programs at interviews?

Some of the most commonly asked pattern programs include pyramid, rhombus, pascal triangle, diamond, mirrored right-angled triangle, downward triangle — composed using stars, alphabets, or numbers.