0

I've found something interesting with my python3.5

So this is the code

previous = 0.1234567891011121314
now = 2.98764627181

print("Before: {0:.15f}".format(float(previous)))
print("Now: {0:.15f}".format(float(now)))


print(" Before:{0:.15f} Now:{0:.15f} ".format(float(previous), float(now)))

and this is the result

Before: 0.123456789101112
Now: 2.987646271810000
Before:0.123456789101112 Now:0.123456789101112

So when I want to print them with one single print and format function python3.5 seems to not able to handle it. Am I doing something wrong?

1
  • Please provide the error or traceback you get that you would like us to help you fix. Commented Feb 8, 2018 at 9:48

1 Answer 1

1

The 0 in the {0:.15f} replacement field is a field name, as specified in the Python documentation for string formatting. When the field name is a number, it identifies a positional argument. Since you have 0 in both replacement fields, both are replaced with the positional argument numbered 0.

To use the other argument, use {1:.15f}.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.