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


 (1).png)