In Python, the range() function generates a sequence of numbers, which is commonly used in for loops to repeat an action a specific number of times. The range() function takes up to three arguments: start, stop, and step. For example:
for i in range(1, 5):
print(i)
This will output numbers from 1 to 4. The for loop iterates over each value generated by range(). You can also use range() to customize the sequence, such as specifying a step value to increment by a certain amount. It helps control loop iterations efficiently.