Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Am I right?
#1
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?
Reply
#2
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}.")
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(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.
Reply
#4
What do you mean when you're saying compiling?
As long as you get the desired output there is nothing wrong.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020