Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (55.6k points)

Can we iterate sequence in python?

1 Answer

0 votes
by (119k points)

Yes, you can use for loops or While loop to iterate sequence as follows:

groceries = ["carrots", "soup", "spinach"]

For Loop:

for grocery in groceries:

    print(grocery)

Output:

carrots

soup

spinach

While Loop:

number = 5

while number < 8:

    print(number)

    number += 1  # increments the number by 1

Output:

5

6

7

I recommend enrolling in this Python Certification Course by Intelllipaat to learn Python.

Also, watch this video on Python Sequences:

Related questions

0 votes
1 answer
0 votes
1 answer
asked Nov 2, 2020 in Python by Sudhir_1997 (55.6k points)
0 votes
1 answer
asked Nov 2, 2020 in Python by Sudhir_1997 (55.6k points)

Browse Categories

...