I was reading "Foundation of python network programming, 2nd edition". And I found in page 22 a sentence which confused me. It's simplified version is like below:
import random
# blah blah blah #
if random.randint(0,1):
print "blah blah blah"
what does random.randint(0,1) do here? Does 0 equal False and 1 equal True here?
random.randint() produces a random integer in the range specified, boundaries included.
Because it produces 0 or 1 at random, and numeric 0 is False and every other number is True, yes, it randomly produces a false or true value.
In Python, empty containers, empty strings, None and numeric 0 (integer 0, float 0.0, etc.) are all false values.
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