Languages
[Edit]
EN

Python - convert string to boolean

0 points
Created by:
Chronal
697

In this article, we would like to show you how to convert string to boolean in Python.

Practical example using bool()

In this example, we use bool() function to convert string and empty_string to the boolean values.

string = "abc"
empty_string = ""

bool_value1 = bool(string)
bool_value2 = bool(empty_string)

print(bool_value1)  # True
print(bool_value2)  # False

print(type(bool_value1))  # <class 'bool'>
print(type(bool_value2))  # <class 'bool'>

Output:

True
False
<class 'bool'>
<class 'bool'>
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Python - string (popular problems)

Python - convert string to boolean
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join