Pythonicness and packaging | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Pythonicness and packaging

What do they mean by this? For I in range(10): I need a more simplified explanation pls, I have a slight migraine! 😩

20th Sep 2020, 11:38 PM
Jordan Alloy ✝️
Jordan Alloy ✝️ - avatar
6 Answers
+ 12
range() returns a list based on the specified argument(s). In this case, range(10) returns a list containing integer values 0 to 9. https://python-reference.readthedocs.io/en/latest/docs/functions/range.html for i in range(10) is basically just a for loop iterating through the values of range(10), where variable i assumes that value. EDIT: Seems like range() returning list is outdated / applies to Python 2 and not 3. Thanks Mirielle[ InAcTiVe ] for pointing that out. I need to be wary of my references. It returns an object of class range instead. print(type(range(10)))
21st Sep 2020, 12:19 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
Just to mention, that range(...) returns a range object / class range r = range(1,10,2) print(r) print(type(r)) # result of the code: range(1, 10, 2) <class 'range'>
21st Sep 2020, 11:15 AM
Lothar
Lothar - avatar
+ 2
Jordan Alloy 😂 bro range() gives us all the numbers coming within the values allotted. Like in range(10), it will give us list with numbers starting from 0 to 9. #as last number is not included.😉
21st Sep 2020, 12:35 AM
Raghvendra Singh Parihar
Raghvendra Singh Parihar - avatar
+ 2
Mirielle[ InAcTiVe ] hmmm I see. Thanks alot
21st Sep 2020, 8:43 AM
Jordan Alloy ✝️
Jordan Alloy ✝️ - avatar
+ 2
Hatsy Rei thanks man. Really comprehensive now
21st Sep 2020, 8:44 AM
Jordan Alloy ✝️
Jordan Alloy ✝️ - avatar
+ 2
Raghvendra Singh Parihar thanks a bunch man
21st Sep 2020, 8:44 AM
Jordan Alloy ✝️
Jordan Alloy ✝️ - avatar