Range Function in Python

Free Video Tutorial and Guide

In this video, we're going to look at how to use the Range Function in Python

Video Transcription

Python for Data Science Bootcamp: Live & Hands-on, In NYC or Online, Learn From Experts, Free Retake, Small Class Sizes,  1-on-1 Bonus Training. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

Hi, my name is Art, and I teach Python at Noble Desktop. In this video, I'm going to show you how to use the built-in Python range function. You can always use help to see the definition of range. Range creates or produces a sequence of integers; it returns a range of numbers.

For example, if you want to get a range of numbers from 1 to 10, it will generate a range of numbers, all of which are numeric data types (integers). Range takes three arguments: start, stop, and step.

Do not confuse these with Python's built-in slicing notation. You can provide just one argument (stop) and the default value for the start point will be zero.

Remember that the stop point is exclusive, so if you pass 5, it will generate a range of numbers from 0 to 4. Most of the time, people use range with a for loop, like "for i in range". If you want to include 5, you need to increase the stop point to 6.

You can also provide a step argument. A step of one means you will get each number in the sequence, while a step of two will skip every other number. To go in descending order, you need to swap the start and stop values and use a negative step.

Try playing around with range, using different numbers and variations. In my next video, I'm going to show you how to use range to generate an index. See you then!

How to Learn Python

Master Python with hands-on training. Python is a popular object-oriented programming language used for data science, machine learning, and web development. 

Yelp Facebook LinkedIn YouTube Twitter Instagram