Get the App
SLTechnology News&Howtos  ›  Development  › 

How python traverses numbers in a range

Shulou Source: shulou.com Published: 2022-06-01 03:55:45 11月13日 Update

Editor to share with you how python traverses a range of numbers, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Traverse a range of numbers

For i in [0,1,2,3,4,5]: print I * * 2for i in range (6): print I * * 2

A better way

For i in xrange (6): print I * 2

Xrange returns an iterator to traverse a range one value at a time. This approach is more memory-efficient than range. Xrange has been renamed range in Python 3.

The above is all the content of the article "how python traverses numbers in a range". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Scope numbers articles content not much memory most ways methods more knowledge industry information information channels channels references learning help iteration Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL OPPO Reno Linux Docker Xiaomi