Well, if you wish for string substitutions, then you can try the following:
>>> "{0}".format("Hello")
'Hello'
>>> "{name}".format(name="Hello")
'Hello'
If you wish to make for
loop constructs, it will be a bit more difficult:
>>> names = ['Joe', 'Bob', 'Stanley', 'Ahmed', 'Inbar', 'Hossain']
>>> var = "".join("{number} -> {name}\n".format(name=name, number=n) for n, name in enumerate(names))
>>> var
'0 -> Joe\n1 -> Bob\n2 -> Stanley\n3 -> Ahmed\n4 -> Inbar\n5 -> Hossain\n'
>>> print var
0 -> Joe
1 -> Bob
2 -> Stanley
3 -> Ahmed
4 -> Inbar
5 -> Hossain
The above is an example of what can be done, of course, you can do things like at li
tags using this kind of formatting:
var = "".join("<li>{name}</li>\n".format(name=name, number=n) for n, name in enumerate(names))
Would produce:
<li>Joe</li>
<li>Bob</li>
<li>Stanley</li>
<li>Ahmed</li>
<li>Inbar</li>
<li>Hossain</li>