Possible Duplicate:
Unpythonic way of printing variables in Python?
In PHP one can write:
$fruit = 'Pear';
print("Hey, $fruit!");
But in Python it’s:
fruit = 'Pear'
print("Hey, {0}!".format(fruit))
Is there a way for me to interpolate variables in strings instead? And if not, how is this more pythonic?
Bonus points for anyone who gets the reference
The way you’re doing it now is a pythonic way to do it. You can also use the locals dictionary. Like so:
Now that doesn’t look very pythonic, but it’s the only way to achieve the same affect you have in your PHP formatting. I’d just stick to the way you’re doing it.