For the sake of learning, is there a shorter way to do:
if string.isdigit() == False :
I tried:
if !string.isdigit() :
and if !(string.isdigit()) :
which both didn't work.
Python's "not" operand is not
, not !
.
Python's "logical not" operand is not
, not !
.
In python, you use the not
keyword instead of !
:
if not string.isdigit():
do_stuff()
This is equivalent to:
if not False:
do_stuff()
i.e:
if True:
do_stuff()
Also, from the PEP 8 Style Guide:
Don't compare boolean values to True or False using ==.
Yes: if greeting:
No: if greeting == True
Worse: if greeting is True:
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