×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python | Program to print a list using 'FOR and IN' loop

Here, we are going to learn how to print elements/objects of a list using FOR and IN loop in Python? By IncludeHelp Last updated : June 21, 2023

print a list using 'FOR and IN' loop

Given a Python list and we have to print its all elements using FOR and IN loop.

'FOR and IN' loop

FOR and IN constructs as loop is very useful in the Python, it can be used to access/traverse each element of a list.

Syntax of for ... in loop

for variable in list_name:
    Statements

Python program to print a list using 'FOR and IN' loop

# 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

Python List Programs »

Advertisement
Advertisement

Related Programs

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.