Python | Ways to concatenate boolean to string
Given a string and a boolean value, write a Python program to concatenate the string with a boolean value, given below are few methods to solve the task.
Method #1: Using format()
# Python code to demonstrate # to concatenate boolean value# with string # Initialising string and boolean valueini_string = "Facts are"value = True # Concatenate using formatres = str(ini_string+" {}").format(value) # Printing resultant stringprint ("Resultant String : ", res) |
Output:
Resultant String : Facts are True
Method #2: Using str
# Python code to demonstrate # to concatenate boolean value# with string # Initialising string and boolean valueini_string = "Facts are"value = True # Concatenate using strres = ini_string +" "+str(value) # Printing resultant stringprint ("Resultant String : ", res) |
Output:
Resultant String : Facts are True
Method #3: Using %s
# Python code to demonstrate # to concatenate boolean value# with string # Concatenate using % sanswer = Trueres = "Facts are %s" %answer # Printing resultant stringprint ("Resultant String : ", res) |
Output:
Resultant String : Facts are True
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.


