Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python | Ways to concatenate boolean to string

  • Last Updated : 29 Jun, 2019

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)
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)
  
         
Output:
Resultant String :  Facts are True

 
Method #3: Using %s




# Python code to demonstrate 
# to concatenate boolean value
# with string
  
# Concatenate using % s
answer = True
res = "Facts are %s" %answer
  
# Printing resultant string
print ("Resultant String : ", res)
  
         
Output:
Resultant String :  Facts are True




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!