[Tutor] if n == 0 vs if not n
Vern Ceder
vceder at canterburyschool.org
Mon Oct 5 21:47:15 CEST 2009
Hi Sander,
PEP 8, the "Style Guide for Python Code"
http://www.python.org/dev/peps/pep-0008/ is pretty clear that the
shorter version is preferable:
if s:
if n:
if b:
if not b:
and so on...
Cheers,
Vern
Sander Sweers wrote:
> Hi Tutors,
>
> I am going through someone's python script and I am seeing a lot of the
> following boolean checks.
>
> if not s == ""
>
> if not n == 0
>
> if b == True
>
> if not b == True
>
> etc..
>
> All of these can be written without the == notation like "if n", "if s"
> etc.
>
> Now in this case where it is only used as boolean checks which would be
> the most pythonic way if writing these checks?
>
> Thanks
> Sander
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
--
This time for sure!
-Bullwinkle J. Moose
-----------------------------
Vern Ceder, Director of Technology
Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804
vceder at canterburyschool.org; 260-436-0746; FAX: 260-436-5137
More information about the Tutor
mailing list