1
first = 'a'
second = 1
third = 'c'

i want the result to be 'a1c' using only first,second and third variables and only string concatenation.

How shall i achieve this.?

user000111181
  • 403
  • 7
  • 19
  • check this out http://www.skymind.com/~ocrow/python_string/ – Saddam Abu Ghaida Nov 17 '12 at 09:34
  • possible duplicate of [How can I concatenate a string and a number in Python?](http://stackoverflow.com/questions/6981495/how-can-i-concatenate-a-string-and-a-number-in-python) – krock Nov 17 '12 at 11:49

2 Answers2

0

You can simply say output = first+str(second)+third This is a duplicate post of How can I concatenate a string and a number in Python?

Community
  • 1
  • 1
Anshul
  • 666
  • 1
  • 5
  • 18
  • but when i give this..!! i get: output=first+second+third Traceback (most recent call last): File "", line 1, in output=first+second+third NameError: name 'second' is not defined – user000111181 Nov 17 '12 at 09:41
  • see edited answer. Also NameError is not expected here. Would help if you can elaborate more on your script (where the variables are declared and which place are they getting concatenated) – Anshul Nov 17 '12 at 09:44
0

You can try "{}{}{}".format(first, second, third).

See string format documentation.

FabienAndre
  • 4,250
  • 21
  • 38