Ads by ProfitSence
Close

Working With Lists in Python

Last Updated on Wednesday 5th Oct 2022

Learn how to loop through an entire list in Python.Looping allows you to take some sort of action with every item in a list.

Looping Through an Entire List

When you want to do the some action with every item in a list, you can use Python’s for in loop.

Let’s say we have a list of students names, and we want to print out each name in the list.

			
					students = ['Adam', 'Dave', 'Ben']
for student in students:
   print(student)

			
	
			
					Adam
Dave
Ben

			
	

You can do just about anything with each item in a for loop.Lets Print a message with the previous example.

			
					students = ['Adam', 'Dave', 'Ben']
for student in students:
  print(f"{student}, I'm Still Studying")

			
	
			
					Adam, I'm Still Studying
Dave, I'm Still Studying
Ben, I'm Still Studying

			
	

To display message like thank you message after the for loop without indentation.

			
					students = ['Adam', 'Dave', 'Ben']
for student in students:
  print(student)

print("Thats the Our Student list")

			
	
			
					Adam
Dave
Ben
Thats the Our Student list