syntax - Unable to understand a line of Python code exactly -


has the following line when translated into English

  print "% 2d .% 8.2f% 8.2f% 8.2f "% (i, payment, interest, month payment)  

I am unsure about the line

  "% 2d.% 8.2f% 8.2f% 8.2f"% # Why do we need the last%?  

It seems that the following

  1. apply% 2d
  2. Apply% 8.2f to make a payment
  3. Apply interest% 8.2f for interest
  4. Pay month by% 8.2f

% -words looks like the following

  1. % 2d.: A decimal presentation of two decades

    2-4% 8.2f: a floating point presentation of two decimal

I'm not sure why we use 8 %% of 8.2f.

How do you understand the challenging line?

8.2 has 8 widths>> "Minimum characters should be printed if printed The value to be less than this number, then the result gets tickled from the spaces. The result is not transformed even when it is large "
The number 2 is the number of decimal places

last% Link in the list of arguments (brackets) with the format string (in quotes). It is a bit confusing that they chose% to do this - maybe there are some deep Python reasons. Edit: Apparently '%' is used only because '%' is used inside the format - which is IMHO Guaranteed to fool and create confusion. This requires an extra point at the end of a floating point number, to show that it is a floating point!


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -