0

How do i concatenate two strings and a number

12th Feb 2017, 4:46 PM
Joshua Sunkwa
Joshua Sunkwa - avatar
3 Answers
+ 13
out = "1"+str(2)+"3"
12th Feb 2017, 4:50 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 6
"ham"+"eggs" + str(2) == "hameggs2" strings are concatenated with + operator. to concatenate a number to a string, convert it to a string with str(your_number)
12th Feb 2017, 4:50 PM
Aidan Haddon-Wright
Aidan Haddon-Wright - avatar
+ 3
With Python3 ( and 2.7 by import print function from __future__ module ^^ ), you can use the format() method of strings: print("my {} string with {} parameters to insert".format("concatenated",2)) Replacement are implicitly in order of the parameters, but coul be write: print("my {1} string with {0} parameters to insert".format(2,"concatenated"))
14th Feb 2017, 6:20 AM
visph
visph - avatar