+ 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! 😩
7 Antworten
+ 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)))
+ 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'>
+ 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.😉
+ 2
Mirielle[ InAcTiVe ] hmmm
I see. Thanks alot
+ 2
Hatsy Rei thanks man. Really comprehensive now
+ 2
Raghvendra Singh Parihar thanks a bunch man