I recently got into code golfing and need to save as many characters as possible.
I remember seeing someone say to use if a/b:
instead of if a<=b:
. However, I looked through Python documentation and saw nothing of the sort.
I could be remembering this all wrong, but I'm pretty sure I've seen this operator used and recommended in multiple instances.
Does this operator exist? If so, how does it work?
Many programming beginners wonder how to write “greater than or equal to” in Python. Well, to write greater than or equal to in Python, you need to use the >= comparison operator. It will return a Boolean value – either True or False. The "greater than or equal to" operator is known as a comparison operator.
That's just division. And, at least for integers a >= 0
and b > 0
, a/b
is truthy if a>=b
. Because, in that scenario, a/b
is a strictly positive integer and bool()
applied to a non-zero integer is True
.
For zero and negative integer arguments, I am sure that you can work out the truthiness of a/b
for yourself.
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