Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: how to make form a string comprising of text and variable values in python 2.6

Tags:

python

string

Basically I'm looking for concatenating the strings and variable together.

In Java:

String s = "HI my name is "+var_name+" I'm "+age+" years old";

In PHP:

$s = "Hi my name is ".$var_name." I'm ".$age." years old";

I want a similar thing in Python. I know the format function supported by Python 3.0 and above but I have a constraint of running it at Python version 2.6. I can't upgrade so please tell me the best method.

P.S - I came to know that format works in Python 2.6 also. If you have any other method please let me know that also. It's always good to know more.

like image 482
Abhishek Avatar asked Jul 07 '26 22:07

Abhishek


1 Answers

.format works on Python 2.6 too:

"Hi my name is {name}. I'm {age} years old.".format(name="John", age=30)
like image 70
nneonneo Avatar answered Jul 10 '26 12:07

nneonneo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!