Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Range in python

Shulou Source: shulou.com Published: 2022-06-01 05:25:36 10月04日 Update

This article is about how to use Range in python. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Range

Typically, when you traverse a list, you access not only the index that has a location in the list, but also the actual elements.

Let's define a list of characters:

X = ['await,' baked,'c']

Instead of traversing it in a standard way, access elements and indexes:

Use enumerations

Enumeration is a built-in function of Python that enables us to iterate over an iterable object and have an automatic counter. It essentially matches each element in the list with the corresponding index. Most newbies, even some senior programmers, don't realize this.

You can change the variables I and v to variable names that you might want to use. For example, for indexes, count in enumerate (x).

Thank you for reading! This is the end of this article on "how to use Range in python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Index element content variable more article good practical advanced Admiral location function name character substance actual object consciousness article novice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Redmi Docker vpn Microsoft