Python 2.7.13
>>> str(b'')
""
>>> bool(str(b''))
False
Python 3.6.0
>>> str(b'')
"b''"
>>> bool(str(b''))
True
My question is two-fold:
- Why does this happen?
- What is the best way to get an empty string from an empty byte string in Python 3.6.0?
bool(str(b""))isTruein 3.6 butFalsein 2.7bool()returns True. Difference is not inboolbut in Python2 vs Python3 differences relating binary strings treatment.bool()and see whatstr(b"")is in the two versions. Hint: it's three characters long in Python 3.