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 in Python by Trisha
10 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 by Priyaj
• 56,140 points

Related Questions In Python

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
• 56,140 points
29 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 in Python by anonymous
34 views
0 votes
1 answer

how to use Binary tree search in Python

The key thing to notice is that ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 56,140 points
48 views
0 votes
1 answer

In python how to test a string for a substring

if "ABCD" in "xxxxABCDyyyy": This can be used ...READ MORE

answered Oct 24, 2018 in Python by Priyaj
• 56,140 points
41 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
56 views
0 votes
1 answer
0 votes
2 answers

How to use threading in Python?

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

answered Apr 6 in Python by anonymous
52 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
• 56,140 points
20 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.