89DEVs

Python: How to convert string to boolean?

How to convert a string to boolean in Python? Use the bool() function.


myString = 'myString'
print(bool(myString))


Returns True, because the string is not empty.

True


myString = ''
print(bool(myString))


Returns False, because the string is empty.

False