For loop in Python

 For loop in Python:

The for loop in Python is used to iterate over a sequence (such as a list, tuple, string, or range) or any iterable object. It allows you to execute a block of code for each item in the sequence.

Here's the syntax of a for loop in Python:

Here are a few examples to illustrate how the for loop works:

  1. Iterating over a list:

Output:

  1. Iterating over a string:

Output:

  1. Using the range() function:

Output:

  1. Skipping iterations using continue:

Output:

  1. Terminating the loop using break:

Output:

These examples demonstrate the basic usage of the for loop in Python. You can use it to perform various operations based on your requirements.

Comments

Popular posts from this blog

Dell New Inspiron 5410 launched .

Why python is an interpreted language?