for num in range(3):
hobby = raw_input("Tell me one of your favorite hobbies: ")
hobbies.append(hobby)
In this for loop, why it will be okay to run without setting a variable called num and add ‘num += 1’ at the end?
for num in range(3):
hobby = raw_input("Tell me one of your favorite hobbies: ")
hobbies.append(hobby)
In this for loop, why it will be okay to run without setting a variable called num and add ‘num += 1’ at the end?
num
is defined when you “declare” the for loop. range()
will produce a list ([0, 1, 2]
) and loop over all the values from this list, then exit when end of list is reached