Page 1 of 1

Python: For Loops

Posted: Tue Jul 22, 2025 11:59 pm
by Jason

Code: Select all

vegetables = {"corn", "carrots", "jalapenos"}

for v in vegetables:

	print(v)
	
# List "vegetables" is declared and listed.

# The list is put into the "for variable" v and looped thru.

#  Loop "v" is printed.

# Note: any single letter can be used as the "for variable".

#  I like to choose ones which also start the main variable for readability. 

Code: Select all

for o in "okra":

	print(o)
	
# The letters in "okra" are put in the "for variable" o and looped thru

# Loop o is printed.
	
# Above prints out individual letters in the word "okra"