When I type in the following code, PyCharm says "Expression can be further simplified". What is the more simplified version to this statement?
if listA == []:
return "yes!"
Empty lists evaluate as falsy, so you can also do this, which is what PyCharm may be talking about:
if not listA:
return "yes!"
There are some side effects since the above code will return "yes!" whenever list is False
, an empty string (""
), None
, an empty dict ({}
), an empty set (set()
) and basically anything else that python treats as falsy
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