Expression can be simplified on list
Piet van Oostrum
piet-l at pietvanoostrum.com
Sat Sep 17 10:13:35 EDT 2016
Daiyue Weng <daiyueweng at gmail.com> writes:
> Hi, I found that when I tried to make an equality test on empty like,
>
> if errors == []:
>
> PyCharm always warns me,
>
> Expression can be simplified.
>
> I am wondering what's wrong and how to fix this?
>
It is not wrong, but it can be simplified to just:
if errors:
This is quite usual in Python, but some people prefer the more elaborate form, or something like:
if len(errors) == 0:
--
Piet van Oostrum <piet-l at pietvanoostrum.com>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
More information about the Python-list
mailing list