I tried the following in the IDLE of Python 3.6
print(value for value in range(1,100))
A message is produced in the IDLE which says
<generator object <genexpr> at 0x101b73a40>
I'm confused what this means. Have I done anything wrong?
C Program to Print 1 to 100 Numbers using While Loop.
(value for value in range(1,100))
produces generator
object, if you want to print list
, just wrap it in []
print([value for value in range(1,100)])
or you can simply
print(list(range(1,100)))
You can read what generators are HERE
A function which returns a generator iterator. It looks like a normal function except that it contains yield expressions for producing a series of values usable in a for-loop or that can be retrieved one at a time with the next() function.
Usually refers to a generator function, but may refer to a generator iterator in some contexts. In cases where the intended meaning isn’t clear, using the full terms avoids ambiguity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With