+ 1
What's a range object and how to convert it to a list
i m new and my first programming language is python so please be clear with me😊
4 odpowiedzi
+ 4
A range is simply a sequence of numbers. So range(10) would give you the sequence 0,1,2,3,4,5,6,7,8,9. They start at 0 unless you specify otherwise, and never include the end limit that you set. range(2,6) would be 2,3,4,5.
If you want you can set a different increment (rather than counting by 1 each time), so range(1,9,2) is 1,3,5,7. You can also have decreasing sequences so range(5,0,-1) is 5,4,3,2,1.
range is of the format range(start limit[optional], end limit[required], increment[optional].
To convert to a list, simply use list(range()).
+ 2
No worries, happy coding!
+ 1
thank u so much that was helpfull i appreciate that
0
thx for you too