Simplifying an If statement with bool()

Gar*_*ary 4 python refactoring boolean lint pylint

I have some code that causes pylint to complain:

The if statement can be replaced with 'var = bool(test)' (simplifiable-if-statement)`

The code (with obfuscated variable names) is below.

A = True
B = 1
C = [1]
D = False
E = False

if A and B in C:
    D = True
else:
    E = True

print(D, E)
Run Code Online (Sandbox Code Playgroud)

How can this be simplified so that pylint does not throw any errors? I don't quite understand how bool() can be used for this. I know it converts any value to a Boolean value, but I don't know how it can be applied here.

ndm*_*iri 5

尝试这个:

D = bool(A and B in C)
E = not bool(A and B in C)
Run Code Online (Sandbox Code Playgroud)


Ste*_*uch 5

That logic can be expressed as:

D = A and B in C
E = not D
Run Code Online (Sandbox Code Playgroud)