0

doubt

iteration = 0 count = 0 while iteration < 5: # the variable 'letter' in the loop stands for every # character, including spaces and commas! for letter in "hello, world": count += 1 print("Iteration " + str(iteration) + "; count is: " + str(count)) iteration += 1 what does for letter in "hello, world" mean and what does it do ?

19th Jun 2018, 6:20 AM
Arunava Sarkar
Arunava Sarkar - avatar
1 Odpowiedź
0
The string "hello, world" will be assigned to the variable letter in a loop, letter by letter 1: letter = h 2: letter = e 3: letter = l and so on. It will be repeated 5 times and the variable count will count the total number of operations. So 12 letters in the string *5 = 60. Whitespace is a letter as well.
19th Jun 2018, 6:29 AM
spotbot2k
spotbot2k - avatar