EN
Python - convert string to boolean
0
points
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'>