+ 1

command " x=(list(range(10)))" converts boolean type to list and assigns it to x?

28th Aug 2020, 6:33 PM
иван
иван - avatar
11 Respostas
+ 5
иван Simple explanation: -> range(a, b) returns numbers from a to b-1, so range(10) would be range(0, 10) would be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Advanced explanation: -> range() is a generator (you'll see this in a later course). When you apply the list() function (or rather change type) to a generator, you will get a list containing the values returned by it (in case it is finite). In your case, range() generator returns values from 0 to n-1 (in case only one parameter is entered, the parameter being n), thus a list from 0 to 9. P.S: -> Don't worry about the details, just understand what it does and move on. Some things can be confusing if you don't know where they're coming from. All you need to know is that range() is used in 'for loops' to easily loop throught values without having to type them one by one.
28th Aug 2020, 6:47 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 5
Where is the boolean?
28th Aug 2020, 6:34 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 4
иван you change it from a generator to a list. The basic difference is that a generator returns values one by one, while a list returns them all at once.
28th Aug 2020, 7:02 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 3
иван where did you see that? Please check the course first before asking questions, it is very well explained there. https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2434/
28th Aug 2020, 6:38 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 3
иван no, but as I've said, it's an advanced concept that you shouldn't bother yourself with at the moment, it will only confuse you.
28th Aug 2020, 7:09 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 3
Aymane Boukrouh well thank you. You helped me very much, thank you very much!
28th Aug 2020, 7:13 PM
иван
иван - avatar
+ 2
I did not get any boolean, I got a list of int's: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Do you want them to be boolean?
28th Aug 2020, 6:37 PM
Steven M
Steven M - avatar
+ 2
Aymane Boukrouh just ... I'm confused. How can a sequence be printed?
28th Aug 2020, 6:41 PM
иван
иван - avatar
+ 2
Aymane Boukrouh From which to which type do I change "range" with the function "list". And why can't you use this command without "list"?
28th Aug 2020, 7:00 PM
иван
иван - avatar
+ 2
Aymane Boukrouh generator is this datatype? О_О
28th Aug 2020, 7:07 PM
иван
иван - avatar
0
Aymane Boukrouh "range", isn't it a boolean?
28th Aug 2020, 6:36 PM
иван
иван - avatar