{"id":34401,"date":"2022-11-19T08:59:21","date_gmt":"2022-11-19T08:59:21","guid":{"rendered":"https:\/\/naiveskill.com\/?p=34401"},"modified":"2022-12-09T14:24:41","modified_gmt":"2022-12-09T14:24:41","slug":"python-range-function","status":"publish","type":"post","link":"https:\/\/naiveskill.com\/python-range-function\/","title":{"rendered":"Python range function detailed tutorial in 2022"},"content":{"rendered":"\n

In this tutorial, I will explain what is python<\/a> range function is and how to use it effectively. I will also explain how to perform various operations using the range function. so let’s get started.<\/p>\n\n\n\n

Python range Function<\/h2>\n\n\n\n
\"Python<\/figure>\n\n\n\n

The Python range function <\/strong>returns a series of numbers, in a given range. The numbers will start from 0 and increment by the step defined.<\/p>\n\n\n\n

Syntax of Python range function<\/h3>\n\n\n\n

Below is the syntax of the range function<\/p>\n\n\n\n

range(start, stop, step)\n\nParameter:\nstart[optional]\t:start value of the sequence\nstop\t\t:end value of the sequence\nstep[optional]\t:an integer number specifying the step to increment.<\/code><\/pre>\n\n\n\n
\"Python<\/figure><\/div>\n\n\n\n

Python range function example<\/h3>\n\n\n\n

Now let’s use the range function to print the numbers from 1 to 5<\/p>\n\n\n\n

# create a sequence of numbers from 1 to 5\nfor i in range(1,5):\n  print(i)<\/code><\/pre>\n\n\n\n
\"Python<\/figure>\n\n\n\n

By default, the step is 1 in the python range function.<\/p>\n\n\n\n

Python range step example<\/h2>\n\n\n\n

So far we have not passed any step into the range function. in this session, we will understand how to use the step-in range function in python.<\/p>\n\n\n\n

# print number from 0 to 11,increment by 2\nfor i in range(0,11,2):\n  print(i)<\/code><\/pre>\n\n\n\n
\"Python<\/figure>\n\n\n\n