What is the difference between a for loop and a while loop?

A for loop will run the code a predetermined number of times, whereas a while loop will continue to execute the code until a predetermined condition is met.

MI

Related Python Mentoring answers

All answers ▸

Sort a given input of lowercase letters alphabetically


What is the outcome of the following code? print(2*[3,4,5])


Write a recursive function to find the factorial of a number n.


Explain why creating a list of several instances of one element using something like my_list = [a] * 5 can result in strange behaviour