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 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 convert Boolean values to integer
- Python | Pandas Series.str.cat() to concatenate string
- Python | Ways to split a string in different ways
- Reverse string in Python (5 different ways)
- Python | Ways to check if given string contains only letter
- Ways to remove i'th character from string in Python
- Find length of a string in python (4 ways)
- Python | Ways to check string contain all same characters
- Python | Ways to find all permutation of a string
- Python | Ways to convert list of ASCII value to string
- Python | Ways to find nth occurrence of substring in a string
- Python | Ways to sort letters of string alphabetically
- Python | Ways to remove numeric digits from given string
- Python | Ways to count number of substring in string
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.



