Python Forum

Full Version: Am I right?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
a = 3
b = 5
print("The product of the two numbers is %d." % a*b)

I don't know that is right.

a = 3
b = 5
print("The product of the two numbers is %d." % a*b)
Am I right?
This is the "old" formatting way. I am saying old but it still works.

Try this one:
print("The product of the two numbers is {}.".format(a * b))
The {} is a placeholder for the format parameters. In this case is just one. The product of two numbers.

The "new" f'string' formatting coming with version 3.6:
print(f"The product of the two numbers is {a*b}.")
(Apr-05-2018, 06:24 AM)wavic Wrote: [ -> ]This is the "old" formatting way. I am saying old but it still works.

Try this one:
print("The product of the two numbers is {}.".format(a * b))
The {} is a placeholder for the format parameters. In this case is just one. The product of two numbers.

The "new" f'string' formatting coming with version 3.6:
print(f"The product of the two numbers is {a*b}.")

Thanks to your tip.
But i still have a question.
print("The product of the two numbers is %d." % a * b)

After I compiled this code, I found that '"The product of the two number is %d" % a' part has priority of compiling. I'm curious that priority of compiling is right.
What do you mean when you're saying compiling?
As long as you get the desired output there is nothing wrong.