How to Convert a String to a Boolean in Python?

5/5 - (1 vote)

You can convert a string value s to a Boolean value using the Python function bool(s).

Here are a few examples:

# True

# True

# False

# True

# True

# True

As you can see, any string will be converted to the Boolean value True–with one exception: the empty string ''.

This is contra-intuitive for many people because they think that the string 'False' should be converted to the Boolean value False. However, this is not the case.

Python is said to be ‘truthy’ which means that it internally converts any object into a truth value if needed. Here’s an example:

x = 'hello world'
y = []

if y:
elif x:

# 42

There is no need to convert the list y or the string x to a Boolean value using the bool() function–Python does it for you!

πŸ‘‰ Recommended Tutorial: How to Convert Boolean to String in Python?

Leave a Comment