if is_ready: already checks whether the value is truthy, so == True is redundant. It's also stricter in a way you might not want: 1 == True is True, but [1] == True is False even though [1] is truthy.
PEP 8 explicitly recommends if is_ready: for booleans.
Comments 5
Join the discussion CommentAlready have an account? Log in
if is_ready:already checks whether the value is truthy, so== Trueis redundant. It's also stricter in a way you might not want:1 == Trueis True, but[1] == Trueis False even though[1]is truthy.PEP 8 explicitly recommends
if is_ready:for booleans.Ok, shorter and more correct. Win-win.
And not just
if not x:when 0 or "" are valid values! That one bit me with a sensor reading of 0.And for None, use
if x is None:, notif x == None:.Good point — the "Missing reading" challenge is built around exactly that 0 vs None trap.