Specifying the increment in for-loops in Python Last Updated : 22 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Let us see how to control the increment in for-loops in Python. We can do this by using the range() function. range() function range() allows the user to generate a series of numbers within a given range. Depending on how many arguments the user is passing to the function, the user can decide where that series of numbers will begin and end as well as how big the difference will be between one number and the next. Syntax: range(start, stop, step) Parameters: start: integer starting from which the sequence of integers is to be returnedstop: integer before which the sequence of integers is to be returnedstep: integer value which determines the increment between each integer in the sequence Returns: a list Example 1: Incrementing the iterator by 1. Python3 for i in range(5): print(i) Output: 0 1 2 3 4 Example 2: Incrementing the iterator by an integer value n. Python3 # increment value n = 3 for i in range(0, 10, n): print(i) Output: 0 3 6 9 Example 3: Decrementing the iterator by an integer value -n. Python3 # decrement value n = -3 for i in range(10, 0, n): print(i) Output: 10 7 4 1 Example 4: Incrementing the iterator by exponential values of n. We will be using list comprehension. Python3 # exponential value n = 2 for i in ([n**x for x in range(5)]): print(i) Output: 1 2 4 8 16 Time complexity: O(n), where n is the number of iterations.Auxiliary space: O(1), as only a constant amount of extra space is used to store the value of "i" in each iteration. Comment More infoAdvertise with us Next Article Specifying the increment in for-loops in Python Y Yash_R Follow Improve Article Tags : Python python-basics Practice Tags : python Similar Reads Unused variable in for loop in Python Prerequisite: Python For loops The for loop has a loop variable that controls the iteration. Not all the loops utilize the loop variable inside the process carried out in the loop. Example: Python3 # i,j - loop variable # loop-1 print("Using the loop variable inside :") # used loop variabl 3 min read Ways to increment Iterator from inside the For loop in Python For loops, in general, are used for sequential traversal. It falls under the category of definite iteration. Definite iterations mean the number of repetitions is specified explicitly in advance. But have you ever wondered, what happens, if you try to increment the value of the iterator from inside 2 min read Understanding for-loop in Python A Pythonic for-loop is very different from for-loops of other programming language. A for-loop in Python is used to loop over an iterator however in other languages, it is used to loop over a condition. In this article, we will take a deeper dive into Pythonic for-loop and witness the reason behind 6 min read Use for Loop That Loops Over a Sequence in Python In this article, we are going to discuss how for loop is used to iterate over a sequence in Python. Python programming is very simple as it provides various methods and keywords that help programmers to implement the logic of code in fewer lines. Using for loop we can iterate a sequence of elements 3 min read Decrement in While Loop in Python A loop is an iterative control structure capable of directing the flow of the program based on the authenticity of a condition. Such structures are required for the automation of tasks. There are 2 types of loops presenting the Python programming language, which are: for loopwhile loop This article 3 min read Like