print("=" * 100 + '\n' + "Can I be more elegant?" + '\n' + "=" * 100)
Is there a better elegant to print this?
Output
========================
Can I be more elegant?
========================
Your first example was better. print("We have x = %i" %x) because you are working with a string object. It takes less memory than working with 2 string objects and an int.
Since you are asking with a python3 tag, here is a newer format for python string formatting using str.format
dic = { 'x': '1'} print("We have x = {x}".format(**dic))
or you can do this positionally:
print("The sum of 1 + 2 is {0}".format(1+2))
This also works with 2.6 and 2.7.
print("{0}\nCan I be more elegant?\n{0}".format("=" * 100))