+ 1
command " x=(list(range(10)))" converts boolean type to list and assigns it to x?
11 Réponses
+ 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.
+ 5
Where is the boolean?
+ 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.
+ 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/
+ 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.
+ 3
Aymane Boukrouh well thank you. You helped me very much, thank you very much!
+ 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?
+ 2
Aymane Boukrouh just ... I'm confused. How can a sequence be printed?
+ 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"?
+ 2
Aymane Boukrouh generator is this datatype? О_О
0
Aymane Boukrouh "range", isn't it a boolean?