Reputation: 4197
I want to call a function in formatted output of string using print(""" """)
function of Python. For example:
print("""
something.......something...
abs(-10.5)
and then again some string......
""")
Is there any way to do it?
Upvotes: 3
Views: 290
Reputation: 336388
This is how you can do it using the new and improved string format
ting method (Python 2.6 and up):
print("""
something.......something...
{0}
and then again some string......
""".format(abs(-10.5)))
Upvotes: 14
Reputation: 16327
You should do it like this:
print("""
something.......something...
%s
and then again some string......
""" % abs(-10.5))
Instead of %s
you can for example use %.3f
which will give you 3 decimals precision, i.e. 10.500. See the docs for more information.
Upvotes: 4