Write a note on different loop statements in python.
In Python, loop statements are used to execute a block of code repeatedly. There are two main types of loops in Python: "for" loops and "while" loops.
for item in iterable: # code block to be executed
fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit)
while condition: # code block to be executed
i = 1 while i < 6: print(i) i += 1
These loops play a crucial role in automating repetitive tasks and iterating through data structures in Python. It's important to use loops efficiently to avoid infinite loops and optimize code execution.