Languages
[Edit]
EN

Python - convert string to boolean

0 points
Created by:
Chronal
337

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'>

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