Python print Boolean as a string | Example code

Use the str method to print the Boolean value as a string in Python.

str(BooleanValue)

Example print Boolean as a string

Simple python example code.

bool_val = True
print(str(bool_val))

print(type(str(bool_val)))

Output:

Python print Boolean as a string

Use + operator with str()

The advantage of converting a boolean into a string you can concatenating a boolean to a string that appends it to the end of another.

bool_val = True
print("This is : " + str(bool_val))

This is : True

Do comment if you have any doubts and suggestions on this Python Boolean string topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.