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 How to Access Index using for Loop - Python When iterating through a list, string, or array in Python, it's often useful to access both the element and its index at the same time. Python offers several simple ways to achieve this within a for loop. In this article, we'll explore different methods to access indices while looping over a sequenc 2 min read Using Else Conditional Statement With For loop in Python Using else conditional statement with for loop in python In most of the programming languages (C/C++, Java, etc), the use of else statement has been restricted with the if conditional statements. But Python also allows us to use the else condition with for loops. The else block just after for/while 2 min read How to print spaces in Python3? In this article, we will learn about how to print space or multiple spaces in the Python programming language. Spacing in Python language is quite simple than other programming language. In C languages, to print 10 spaces a loop is used while in python no loop is used to print number of spaces. Foll 2 min read How to Decrement a Python for Loop Pythonâs for loop is commonly used to iterate over sequences like lists, strings, and ranges. However, in many scenarios, we need the loop to count backward. Although Python doesn't have a built-in "decrementing for loop" like some other languages (e.g., for(int i = n; i >= 0; i--) in C++), there 2 min read Increment += and Decrement -= Assignment Operators in Python If you're familiar with Python, you would have known Increment and Decrement operators ( both pre and post) are not allowed in it. Python is designed to be consistent and readable. One common error by a novice programmer in languages with ++ and -- operators are mixing up the differences (both in pr 3 min read Like