0
what is the output for the below code? Print(range(0, 8,2)) . Can anyone explain it how we are getting it
Range in python
7 Antworten
+ 3
You can copy it onto playground and check out what happens!
It's giving a range of integers
The 1st argument is the starting value, the 2nd the end value (exclusive), the 3rd is the step-size.
+ 3
Oh, okay. To be precise, range() returns the object that generates the sequence (not the sequence itself). If we put list() around range() we get the actual sequence.
+ 3
range() gives a ***range object***
+ 1
Hi hemu!
That's because, range(10) returns an object that prints as range(10) (since it shows the starting value when it prints) and whose elements are the integers from 0 to 9, so range(10) gives the one-element list (range( 10)) and list(range(10)) gives the 10-element list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].
We can also use list unpacking instead.
https://code.sololearn.com/cHTazGEMLZvc/?ref=app
+ 1
Thanks Lisa and python learner
0
I tried in python got the Output as range(0, 8,2) . Didn't understand why it got print as the same
0
Yeah i understood the range function how it works.... But confused with this output..... Do you mean giving range function inside print will take it as a statement and print the same