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 value ini_string = "Facts are"value = True # Concatenate using format res = str(ini_string+" {}").format(value) # Printing resultant string print ("Resultant String : ", res) |
chevron_right
filter_none
Output:
Resultant String : Facts are True
Method #2: Using str
# Python code to demonstrate # to concatenate boolean value # with string # Initialising string and boolean value ini_string = "Facts are"value = True # Concatenate using str res = ini_string +" "+str(value) # Printing resultant string print ("Resultant String : ", res) |
chevron_right
filter_none
Output:
Resultant String : Facts are True
Method #3: Using %s
# Python code to demonstrate # to concatenate boolean value # with string # Concatenate using % s answer = Trueres = "Facts are %s" %answer # Printing resultant string print ("Resultant String : ", res) |
chevron_right
filter_none
Output:
Resultant String : Facts are True
Recommended Posts:
- Python | Ways to concatenate two lists
- Python | Ways to concatenate tuples
- Python | Ways to convert Boolean values to integer
- Python | Pandas Series.str.cat() to concatenate string
- Python | Concatenate N consecutive elements in String list
- Python - Concatenate Dictionary string values
- Python - Concatenate string rows in Matrix
- Python - Concatenate String values in Dictionary List
- Python - Concatenate Ranged Values in String list
- Python - Concatenate Random characters in String List
- Python program to Concatenate Kth index words of String
- Python | Ways to split a string in different ways
- Python | Merge, Join and Concatenate DataFrames using Panda
- Python | Concatenate two lists element-wise
- Python | Concatenate dictionary value lists
- Python | Numpy np.ma.concatenate() method
- Python | How to Concatenate tuples to nested tuples
- Python - Concatenate Kth element in Tuple List
- Python - Concatenate consecutive elements in Tuple
- Python | Concatenate All Records
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

