The length of a collection is always greater than or equal to zero. So testing that a length is greater than or equal to zero doesn’t make sense,
since the result is always true
. Similarly testing that it is less than zero will always return false
. Perhaps the intent
was to check the non-emptiness of the collection instead.
Noncompliant Code Example
mylist = []
if len(myList) >= 0: # Noncompliant
pass
if len(myList) < 0: # Noncompliant
pass
Compliant Solution
mylist = []
if len(myList) >= 42:
pass
if len(myList) == 0:
pass