Dave Angel wrote:

Now in this case where it is only used as boolean checks which would be
the most pythonic way if writing these checks?


The shorter version may be preferable, but it doesn't generally give the same results. Without knowing the possible data, these substitutions are not safe.

For example, replacing       "if not n == 0"    with     "if n"

will give different results for values of "", [] and so on. It WILL work if you know that n is an int or float, however.

DaveA

True, I took the OP's statement that they were to be used "only as boolean checks" to mean that there was no type mixing going on. Personally, I would say that checking a list or string for equality (or lack thereof) with 0 is even less "preferable". ;)

Otherwise, one would at least prefer "if n != 0" to "if not n == 0", I would think.

Cheers, Vern
--
This time for sure!
   -Bullwinkle J. Moose
-----------------------------
Vern Ceder, Director of Technology
Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804
vce...@canterburyschool.org; 260-436-0746; FAX: 260-436-5137
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to