I have the following code that reproduces a PyCharm warning,
Expression can be simplified
This expression detects equality comparison with a boolean literal.
seq_group = []
if seq_group == []: # warning here
print("it is empty.")
if I change the code to,
if seq_group is None:
will fix the warning, but the real question is are None and []emplty list the same thing?
cheers
are
Noneand[]empty list the same thing?
Nope, and it will result in erroneous behavior:
seq_group = []
if seq_group is None:
print("it is empty")
This doesn't print anything, None is completely different to [], value and identity wise. None indicates the absence of a value, [] indicates a list with no values. The confusion might arise from the fact that both happen to evaluate False in conditionals.
The warning is probably due to the fact that you can simply use seq_group with not instead of using a literal with ==:
if not seq_group:
print("it is empty")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With