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

Full-Stack Web Development Certificate: Live & Hands-on, In NYC or Online, 0% Financing, 1-on-1 Mentoring, Free Retake, Job Prep. 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 Coding

Master coding with hands-on training. Learning how to code in JavaScript, Python, and other popular languages can pave the way to a job in tech, such as web development, data science & analytics, or software engineering.

Yelp Facebook LinkedIn YouTube Twitter Instagram