Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the for Loop statement of python

Shulou Source: shulou.com Published: 2022-06-01 03:54:37 09月26日 Update

This article mainly explains "how to use the for loop sentence of python". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the for loop sentence of python.

Example of for Loop statement

Enter:

#! / usr/bin/python

# Filename: for.py

For i in range (1,5):

Print (I)

Else:

Print ('The for loop is over')

Output:

one

two

three

four

The for loop is over

Explanation:

For variable name in range / condition:

Statement

Else:

Statements after the completion of the for loop

In this case, the variable is in the range of I and the condition is (1BI 5), but it only means iMagic 1, 2, 2, 3, 3, 4. The condition here is left open and right closed.

All conditions are executed once, and the loop ends after execution.

At this point, I believe you have a deeper understanding of "how to use the for loop statement of python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Statements loops conditions content variables scope learning practicality deeper interest practicality practicality simple operation methods more friends examples websites channels queries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology Shulou Information Docker Linux