What exactly does the following statement mean in Python?
randrange(10**10) for i in range(100)
I'm aware that randrange
is a random number generator but cant really make out the effect of the statement.
The way you posted it, it's a SyntaxError
.
But I guess the statement is inside []
. Then it's a list comprehension which creates a list containing 100 random numbers. It is equivalent to this code:
whatever = []
for i in range(100):
whatever.append(randrange(10**10))
If the code was inside ()
instead of []
it would be a generator expression, i.e. an iterable whose items are not created immediately but on demand.
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