Different ways to convert one boolean to string in python

Introduction :

Boolean values are True and False. Sometimes we may need to convert these values to string. In python, we have different ways to do that and in this post, I will show you three different ways to convert one boolean value to string in python.

Method 1: Using format :

Using format, we can format one boolean value to string. For example :

bool_true = True
bool_false = False

print('bool_true = {}'.format(bool_true))
print('bool_false = {}'.format(bool_false))

This will print :

bool_true = True
bool_false = False

Method 2: Using %s :

%s is used to format values into string. We can use this to format boolean values to string as like below :

bool_true = True
bool_false = False

print('bool_true = %s'%bool_true)
print('bool_false = %s'%bool_false)

It will print the same output.

Method 3: Using str() :

Another way to convert one boolean to string in python :

bool_true = True
bool_false = False

print('bool_true = '+str(bool_true))
print('bool_false = '+str(bool_false))

It will print the same output.

All methods give the same output. You can use any one of them.

Where is the color and why codevscolor ?

Long story short, I love paintings and I paint on weekends. We(me and my wife) have one Youtube channel. Below is a video that I did recently. If you love this please do subscribe to support us 😊