How to use for loop in Python

0 votes
Can someone tell me how to use for loop in Python? I am new to Python. Thank you.
Mar 4, 2019 in Python by Trisha
491 views

1 answer to this question.

0 votes

There are multiple ways of using for loop in Python.

1. To iterate within a String

for letter in 'Priyaj':
   print 'Letter Present:', letter #This will print letters in the string that you iterate.

2. To iterate in an array/list

letter = ['a', 'b',  'c']
for index in range(len(letter)): #this will iterate through the element of the list/array
   print 'Current fruit :', letter[index]

3. To iterate in a range

for index in range (10,20): #this will iterate between 10 - 20
   print 'Current Number:', index 

Hope this helps.

answered Mar 4, 2019 by Priyaj
• 58,090 points

Related Questions In Python

0 votes
2 answers

How to use in python for loop not equal marks? example: a!=0

Hello @Azizjon, You can go through the example ...READ MORE

answered Oct 12, 2020 in Python by Gitika
• 65,910 points
1,934 views
0 votes
0 answers
0 votes
1 answer

How to use string.replace() in python 3.x

replace() is a method of <class 'str'> ...READ MORE

answered Aug 3, 2018 in Python by Priyaj
• 58,090 points
864 views
+1 vote
2 answers

How to use the pass statement in Python

In Python programming, pass is a null statement. The ...READ MORE

answered Apr 5, 2019 in Python by anonymous
763 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,055 views
0 votes
1 answer
0 votes
1 answer

Python: For loop to iterate class object

Refer to the below code: class Try: ...READ MORE

answered May 22, 2019 in Python by Raj
7,693 views
0 votes
2 answers

How to use threading in Python?

 Thread is the smallest unit of processing that ...READ MORE

answered Apr 6, 2019 in Python by anonymous
1,050 views
0 votes
1 answer

How to use “raise” keyword in Python

You can use it to raise errors ...READ MORE

answered Jul 30, 2018 in Python by Priyaj
• 58,090 points
501 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP