Expedia Code Academy
expedia_brands = ['Hotels.com', 'EPS', 'Expedia']
for brand in expedia_brands:
print('I love ' + brand)
for scoobydoo in expedia_brands: # same as the above for loop
print('I love ' + scoobydoo)
The word variable is recreated every round of the loop, with the value of the next item in the list.
You can name it anything you like! Just use the same variable name within the for loop.
What do we think this code will do?
my_string = 'Today is a great day!'
print(my_string[0])
Strings are simply lists of characters!
total = 0
my_string = 'Today is a great day!'
for letter in my_string:
???
(⭐️) 4c. Count the number of 'a's in my_string.
While loops are useful when you want something to loop forever, or until something changes!
For loops are useful when you have your data already and want to loop through it until it ends.
What about these examples?
some_numbers = [1.5, 37.2, 55, -1.94]