How to convert a boolean into string in Python
In this tutorial, we are going to learn about how to convert the boolean to a string in Python.
Converting boolean to string
To convert a boolean to string, we can use the str() function in Python.
The str() function takes the Boolean value as an argument and converts it to the string.
Here is an example, that converts the boolean True
to a string value:
active = True
a = str(active)
print(a)
Output:
'True'
or we can use the python string interpolation to convert the boolean to string.
Here is an example:
active = True
a = f"All are {active}"
print(a)
Output:
'All are True'
You can also check out how to convert string to boolean in Python.