Devnote

Web Development Blog Company, Services India

MySQL Error 121 Duplicate key on write - Practical Repair Strategy
MySQL Error 121 Duplicate key on write – Practical Repair Strategy
February 13, 2026
PHP cURL error 60: SSL certificate problem - Windows & Linux Fix
PHP cURL error 60: SSL certificate problem – Windows & Linux Fix
February 11, 2026
Fix localhost refused to connect After Installing XAMPP / WAMP
Fix “localhost refused to connect” After Installing XAMPP / WAMP
February 9, 2026
Composer Error Memory exhausted When Installing Packages - Real Fix
Composer Error: Memory exhausted When Installing Packages – Real Fix
February 6, 2026
MySQL 8 Error Unknown collation: utf8mb4_0900_ai_ci - Safe Migration Guide
MySQL 8 Error Unknown collation: utf8mb4_0900_ai_ci – Safe Migration Guide
February 4, 2026
Devnote

Type and hit Enter to search

  • Home
  • Laravel
    • Auth
    • Migration
    • DATATABLE
    • Yajra
  • wordpress
    • plugin
    • WPBakery
    • woocommerce
  • PHP
    • MYSQL
    • Ajax
  • Blog
  • Informational
    • About us
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact US
Devnote
  • Home
  • Laravel
    • Auth
    • Migration
    • DATATABLE
    • Yajra
  • wordpress
    • plugin
    • WPBakery
    • woocommerce
  • PHP
    • MYSQL
    • Ajax
  • Blog
  • Informational
    • About us
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact US
Python looping statement

Python looping statement

Image
Devnote team
November 20, 2020
2
597 Views
0 Comments

This tutorial is a Python looping statement. A looping statement is used in the programming language that allows us to repeat a block of the code a number of times.

Python has two types of loops available:

  1. While loop
  2. For loop

You can also specify else block with looping statement.

While

while loop executes a block of code until the specified condition is true otherwise
terminate the loop.

Syntax

while expression :
    # statement

Example

year = 2001
while year <= 2005 :
    print("Year :",year)
    year+=1

Output:
Year : 2001
Year : 2002
Year : 2003
Year : 2004
Year : 2005

While else

else block executes only when the loop terminates normally not by a break statement.

Syntax

while expression :
    # statement
else:
    # else statement

Example

year = 2001
while year <= 2005 :
    print(year)
    year+=1
else:
    print("year is no longer less than 2006")

Output:
2001
2002
2003
2004
2005
year is no longer less than 2006

For

For loop mostly used for looping over sequences list, tuple, dictionary. for loop executes it stores the first item in loop variable and execute the block code until the sequence is not empty.

Syntax

for variable in sequence :
    # statement

Example

years = [2001,2002,2003,2004,2005]
for year in years :
    print("Year :",year)

Output:
Year : 2001
Year : 2002
Year : 2003
Year : 2004
Year : 2005

For else

for else executes when loop terminates normally not by using break statement.

Syntax

for variable in sequence :
    # statement
else:
    # else statement

Example

years = [2001,2002,2003,2004,2005]
for year in years :
    print("Year :",year)
else:
    print("Years is empty")

Output:
Year : 2001
Year : 2002
Year : 2003
Year : 2004
Year : 2005
Years is empty

Categories:

python

Other Articles

Allowed memory size of 134217728 bytes exhausted
Previous

The allowed memory size of 134217728 bytes exhausted

facebook sign up button
Next

Laravel Facebook Login with Socialite Step by Step Guide

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

How to add a date filter to Django admin?

How to add a date filter to Django admin?

February 1, 2021
How to remove default apps in Django admin?

How to remove default apps in Django admin?

January 29, 2021
Remove an item from a list in Python

How to remove an item from a list in Python

January 28, 2021
How to change Django administration text?

How to change Django administration text?

January 25, 2021
Devnote

Devnote provides a collection of tutorials about PHP, Laravel, WordPress, Django, MySQL, Bootstrap, Jquery, Ajax, APIs, CRUD operations, etc.

Devnote © , All Rights Reserved.

Page Links

  • Home
  • About us
  • Blog
  • Contact US
  • Site map

Category

  • PHP
  • Laravel
  • wordpress
  • HTML
  • jQuery

Follow Us

Facebook Instagram Twitter Youtube Linkedin Pinterest
Morbi, Gujarat, India - 363641
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT
Advertisement