Quick actions

cmd+k|ctrl+k

Navigation

Languages

forloop_loopingthroughalist

Snippet info

Language

Python

Visibility

public

Author

masterhun

Created

2023-09-13T17:59:15.207791Z

Updated

2023-09-13T18:05:11.214379Z

print("for loops")


print()

# Looping through at list of integers 

numbers = [12, 13, 14, 15, 16, 17]

total = 0

print("Looping through at list of integers")

for number in numbers:
    print(number)
    total = total + number     # Addtion + 

print("Total: " + str(total))

print()

# Looping through a list of strings 

numbers = ['12', '13', '14', '15', '16', '17']

total = ""     # a string variable, "" is the empty string 

print("Looping through a list of strings")

for number in numbers:
    print(number)
    total = total + number      # Not addtion, but concatenation 

print("Total: " + total)

print()


# Looping through at string

beans = "this is a test"     # FYI: A space is also a character, if not a letter.

print("Looping through at string")

for letter in beans:
    print(letter)
    
print(beans)


# THE END 
INFO