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

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.

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.

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!

photo of Noble Desktop

Noble Desktop

At Noble Desktop you can learn how to code websites, build iOS apps, make graphics, and more. From our front-end coding bootcamp to Photoshop classes, we offer a variety of comprehensive day, evening, and weekend training classes as well as certificate programs in web design, web development, HTML email, and more. Courses are available in-person (at our training facility in Soho), live online, and customized corporate or private training. Our course materials and workbooks are used by colleges and schools worldwide. Learn a skill today and start using it tomorrow.

More articles by Noble Desktop

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