Python Program to print a list using ‘FOR and IN’ loop

Here, we will figure out how to print components/objects of a rundown utilizing FOR and IN circle in Python?

Given a rundown and we need to print its everything components utilizing FOR and IN circle in Python.

FOR and IN builds as the circle is valuable in the Python, it tends to be utilized to get to/cross every component of a rundown.

Sentence structure of for … in the loop.

    for variable in list_name:
        Statements

Example/Programs: Declaring and printing a rundown:

# Declaring a list
list = [10, 20, 30, 40, 50]

# printing without using FOR and IN
print "List elements are: ", list
print " " # prints new line

# printing using FOR and IN
print "List elements are: "

for L in list:
	print L 

print " " # prints new line

# calculating Sum of all elements
sum = 0 
for L in list:
	sum += L 
print "Sum is: ", sum

Output:

    List elements are:  [10, 20, 30, 40, 50]
 
    List elements are: 
    10
    20
    30
    40
    50
 
    Sum is:  150

Leave a Comment

error: Alert: Content is protected!!